目录

Configuring a Prompt Template

Function Description

A prompt template uses a structured and fixed format to clearly organize elements such as roles, tasks, and input and output requirements. This allows you to fill in only key information to guide the model to generate expected results in a stable and efficient manner. You can import a custom prompt template by placing the prompt_template.json configuration file in the specified app's resource directory.

Each RAG prompt template set contains system prompts and user prompts. The format is as follows:

"Prompt template set name": {
    "system": "XXX",
    "user": "XXX"
}

RAG supports three custom prompt template sets and provides placeholders to be replaced with the corresponding content. A placeholder can be used multiple times in a template, and each placeholder will be replaced with the corresponding content.

Prompt Template Set Name Prompt Template Set Description Placeholder Placeholder Replacement
coreferencePrompt Coreference resolution prompt template set {history} Historical Q&A records used to guide coreference resolution during the resolution stage.
coreferencePrompt Coreference resolution prompt template set {input} User input during the coreference resolution stage.
extractionPrompt Keyword extraction prompt template set {question} User input during the keyword processing stage.
answerPrompt Summarization prompt template set {history} Historical Q&A records of a user during the summarization stage.
answerPrompt Summarization prompt template set {time} Time information during the summarization stage.
answerPrompt Summarization prompt template set {query} User input during the summarization stage.
answerPrompt Summarization prompt template set {retrieval} Retrieval result information used to support summarization during the summarization stage.

Constraints

  1. The hyperparameter name in the configuration file must be the same as the specified name. That is, the key of the template set must be coreferencePrompt, extractionPrompt, or answerPrompt. Each prompt template set must contain both system prompts and user prompts.

  2. The data type of a prompt template must be a string. Otherwise, the template may fail to be loaded.

  3. It is recommended that the length of the prompt template comply with the configuration of the actually used LLM.

Development Procedure

Create the prompt_template.json file in rawfile/arkdata/rag in the resource directory of the app. If the target directory does not exist in the project, create it recursively.

The following is an example of the prompt template file prompt_template.json. Configure the actual file content based on service requirements.

{
    "coreferencePrompt": {
        "system": "This is a coreference system prompt.",
        "user": " This is a coreference user prompt.\nPrompt history: {history}; Prompt input: {input}."
    },
    "extractionPrompt": {
        "system": "This is extraction system prompt.",
        "user": " This is extraction user prompt.\nPrompt question: {question}. "
    },
    "answerPrompt": {
        "system": "This is answer system prompt.",
        "user": " This is answer user prompt.\nPrompt history: {history};Prompt time: {time};Prompt query: {query};Prompt retrieval: {retrieval}."
    }
}