Optimizing prompts helps you achieve more accurate and relevant results from a large language model. Alibaba Cloud OpenSearch LLM-based Edition allows you to create custom prompt templates tailored to your specific business needs. This topic explains how to create and manage custom prompt templates.
Create a prompt template
The system provides a default prompt template that prevents the large language model from using public content when no search results are found. To create a custom template, go to Prompt Management > Create Template. On the Create Prompt Template page, enter a Prompt Template Name, Template Description, and the message, and click Confirm.
Parameters
Prompt Template Name: Required. The name must be 1 to 30 characters long, start with a letter, and contain only uppercase and lowercase letters, digits, and underscores (_). The name must be unique.
Template Description: Optional. The description must be 1 to 30 characters long, start with a letter, digit, or Chinese character, and can contain letters, digits, Chinese characters, underscores (_), and hyphens (-).
message: The message consists of one or more pairs of role and content. Click "+" to add a new pair. The available roles are system, user, and assistant. The content for each role must not be empty, exceed 1,024 characters, or contain the <# or [# character sequences.
-
system: Provides system-level instructions. It has the highest priority and can be used to guide the model to generate output according to a predefined function, specification, or persona.
-
user: Represents the user's input. In a conversation,
userandassistantroles should alternate to simulate a natural conversation. -
custom variable: You can use custom variables in a prompt. The syntax is
${parameters.variable_name}. A variable name must be 1 to 64 characters long and can contain only uppercase and lowercase letters, digits, and underscores (_).When you define a custom variable, you must set a default value. Use one of the following formats:
-
${(parameters.name)!}: Sets the default value to an empty string.
-
${(parameters.name)!"large language model"}: Sets the default value to
large language model.
-
This defines the final prompt that is sent to the large language model. You can pass values by using variables. If you define variables, you must provide their corresponding values through the API and follow the specified syntax. Custom variable names cannot conflict with built-in variables. The built-in variables are:
-
{question}: The original query entered by the user. -
{docs}: The content generated by concatenating documents according to the specified format.
Message examples
After you create the template by clicking Confirm, click Q&A Test to open the Q&A Test page. For the following examples, assume that the knowledge base has been pre-populated with information about Cloud Search Engine:
-
Default template
Role
Content
Intelligent response
Prompt template behavior
system
You are a helpful assistant.
Q: What is 1+1?
A: I cannot answer this question based on the provided information.
Q: What is Cloud Search Engine?
A: Cloud Search Engine is a search engine that uses cloud computing technology. It has the following features: 1. You can bind multiple domain names to define search scopes and properties. 2. Different domain names can have different user interfaces (UIs) and search processes, and these UIs and processes are...
-
For questions outside the knowledge base: When no search results are found, the model does not use public content. It answers only based on the provided information, ensuring the reliability and accuracy of the response.
-
For questions within the knowledge base: The model provides accurate and reliable answers based on the provided information.
user
The provided information consists of multiple independent documents, each enclosed in <article> and </article> tags. The information is as follows:
'''${docs}'''
Based on the information provided above, answer the user's question in a detailed and organized manner. Ensure that your answer fully addresses the question and correctly uses the provided information. If the information is insufficient to answer the question, state "I cannot answer this question based on the provided information." Do not use any information that is not in the provided documents. Ensure that every statement in your answer is supported by the provided information. Please answer in Chinese.
The question is: '''${question}'''
-
-
If you want the model to use public content to answer when no search results are found, you can create a custom template as follows:
Role
Content
Intelligent response
Prompt template behavior
system
You are a helpful assistant.
Q: What is 1+1?
A: 1+1=2.
Q: What is Cloud Search Engine?
A: Cloud Search Engine is a search engine that uses cloud computing technology. It has the following features: 1. You can bind multiple domain names to define search scopes and properties. 2. Different domain names can have different user interfaces (UIs) and search processes, and these UIs and processes are...
-
For questions outside the knowledge base: When no search results are found, the model uses public content to answer.
-
For questions within the knowledge base: The model provides accurate and reliable answers based on the provided information.
user
The provided information consists of multiple independent documents, each enclosed in <article> and </article> tags. The information is as follows:
'''${docs}'''
You are knowledgeable about many subjects, including mathematics. Please accurately answer the following question.
The question is: '''${question}'''
-
-
If you need to use a custom variable in the prompt, you can define it by using the format
${(parameters.variable_name)!"default_value"}:Role
Content
Q&A test
Prompt template behavior
system
You are a helpful assistant.
Model: opensearch-qwen
You can view custom variables on the Q&A Test > Prompt Parameters page.
Q: What is 1+1?
A: I cannot answer this question based on the provided information. The information does not contain any content related to mathematical calculations. It only provides an introduction to Alibaba Cloud OpenSearch LLM-based Edition and Alibaba Cloud services, and descriptions of some services and products, without any mention of mathematical operations.
You can edit the variable's value directly in the console:
Q: What is 1+1?
A: I am very sorry. Based on the information you provided, I cannot answer questions about mathematical calculations because the provided text does not contain any relevant information. If you need to solve a math problem, please provide the relevant information or use a calculation tool.
A custom variable named
no_answeris defined. When the information is insufficient to answer a question, the model outputs the default value of theno_answervariable: "I cannot answer this question based on the provided information." By changing the variable's value, the model's output changes to "I am very sorry".user
The provided information consists of multiple independent documents, each enclosed in <article> and </article> tags. The information is as follows:
'''${docs}'''
Based on the information provided above, answer the user's question in a detailed and organized manner. Ensure that your answer fully addresses the question and correctly uses the provided information. If the information is insufficient to answer the question, state ${(parameters.no_answer)!"I cannot answer this question based on the provided information."} Do not use any information that is not in the provided documents. Ensure that every statement in your answer is supported by the provided information. Please answer in Chinese.
The question is: '''${question}'''
Manage prompt templates
After you create a template, you can manage all your prompt templates on the Prompt Management page. You can view, edit, and delete templates. On the Intelligent Conversation page, you can select an existing prompt template to create a new intelligent conversation and use it for Q&A testing.
-
The default prompt template cannot be edited.
-
When you edit a prompt template, you cannot change the prompt template name, but you can modify all other settings.