From 5e05f43c3d0f2c7ffa5c6c352e7473eac8560b4b Mon Sep 17 00:00:00 2001 From: Jin Hai Date: Wed, 17 Dec 2025 12:57:24 +0800 Subject: [PATCH] Update default prompt (#11984) ### What problem does this PR solve? New default prompt: ``` You are an intelligent assistant. Your primary function is to answer questions based strictly on the provided knowledge base. **Essential Rules:** - Your answer must be derived **solely** from this knowledge base: `{knowledge}`. - **When information is available**: Summarize the content to give a detailed answer. - **When information is unavailable**: Your response must contain this exact sentence: "The answer you are looking for is not found in the knowledge base!" - **Always consider** the entire conversation history. ``` Also fix some grammar errors. ### Type of change - [x] Refactoring Signed-off-by: Jin Hai --- agent/test/dsl_examples/retrieval_and_generate.json | 2 +- agent/test/dsl_examples/tavily_and_generate.json | 2 +- sdk/python/ragflow_sdk/modules/chat.py | 10 ++++++---- sdk/python/ragflow_sdk/ragflow.py | 10 ++++++---- web/src/locales/en.ts | 11 +++++++---- 5 files changed, 21 insertions(+), 14 deletions(-) diff --git a/agent/test/dsl_examples/retrieval_and_generate.json b/agent/test/dsl_examples/retrieval_and_generate.json index b392962e28..3897e877fd 100644 --- a/agent/test/dsl_examples/retrieval_and_generate.json +++ b/agent/test/dsl_examples/retrieval_and_generate.json @@ -31,7 +31,7 @@ "component_name": "LLM", "params": { "llm_id": "deepseek-chat", - "sys_prompt": "You are an intelligent assistant. Please summarize the content of the knowledge base to answer the question. Please list the data in the knowledge base and answer in detail. When all knowledge base content is irrelevant to the question, your answer must include the sentence \"The answer you are looking for is not found in the knowledge base!\" Answers need to consider chat history.\n Here is the knowledge base:\n {retrieval:0@formalized_content}\n The above is the knowledge base.", + "sys_prompt": "You are an intelligent assistant. Please summarize the content of the knowledge base to answer the question. Please list the data in the knowledge base and answer in detail. When all knowledge base content is irrelevant to the question, your answer must include the sentence \"The answer you are looking for is not found in the knowledge base!\" Answers need to consider chat history.\n Here is the knowledge base:\n {retrieval:0@formalized_content}\n Above is the knowledge base.", "temperature": 0.2 } }, diff --git a/agent/test/dsl_examples/tavily_and_generate.json b/agent/test/dsl_examples/tavily_and_generate.json index caa10d1556..95739224a0 100644 --- a/agent/test/dsl_examples/tavily_and_generate.json +++ b/agent/test/dsl_examples/tavily_and_generate.json @@ -25,7 +25,7 @@ "component_name": "LLM", "params": { "llm_id": "deepseek-chat", - "sys_prompt": "You are an intelligent assistant. Please summarize the content of the knowledge base to answer the question. Please list the data in the knowledge base and answer in detail. When all knowledge base content is irrelevant to the question, your answer must include the sentence \"The answer you are looking for is not found in the knowledge base!\" Answers need to consider chat history.\n Here is the knowledge base:\n {tavily:0@formalized_content}\n The above is the knowledge base.", + "sys_prompt": "You are an intelligent assistant. Please summarize the content of the knowledge base to answer the question. Please list the data in the knowledge base and answer in detail. When all knowledge base content is irrelevant to the question, your answer must include the sentence \"The answer you are looking for is not found in the knowledge base!\" Answers need to consider chat history.\n Here is the knowledge base:\n {tavily:0@formalized_content}\n Above is the knowledge base.", "temperature": 0.2 } }, diff --git a/sdk/python/ragflow_sdk/modules/chat.py b/sdk/python/ragflow_sdk/modules/chat.py index 5935b5b708..53fcc1af95 100644 --- a/sdk/python/ragflow_sdk/modules/chat.py +++ b/sdk/python/ragflow_sdk/modules/chat.py @@ -50,10 +50,12 @@ class Chat(Base): self.opener = "Hi! I'm your assistant. What can I do for you?" self.show_quote = True self.prompt = ( - "You are an intelligent assistant. Please summarize the content of the knowledge base to answer the question. " - "Please list the data in the knowledge base and answer in detail. When all knowledge base content is irrelevant to the question, " - "your answer must include the sentence 'The answer you are looking for is not found in the knowledge base!' " - "Answers need to consider chat history.\nHere is the knowledge base:\n{knowledge}\nThe above is the knowledge base." + "You are an intelligent assistant. Your primary function is to answer questions based strictly on the provided knowledge base." + "**Essential Rules:**" + "- Your answer must be derived **solely** from this knowledge base: `{knowledge}`." + "- **When information is available**: Summarize the content to give a detailed answer." + "- **When information is unavailable**: Your response must contain this exact sentence: 'The answer you are looking for is not found in the knowledge base!' " + "- **Always consider** the entire conversation history." ) super().__init__(rag, res_dict) diff --git a/sdk/python/ragflow_sdk/ragflow.py b/sdk/python/ragflow_sdk/ragflow.py index f200a6b5c6..e46023177d 100644 --- a/sdk/python/ragflow_sdk/ragflow.py +++ b/sdk/python/ragflow_sdk/ragflow.py @@ -146,10 +146,12 @@ class RAGFlow: prompt.opener = "Hi! I'm your assistant. What can I do for you?" if prompt.prompt is None: prompt.prompt = ( - "You are an intelligent assistant. Please summarize the content of the knowledge base to answer the question. " - "Please list the data in the knowledge base and answer in detail. When all knowledge base content is irrelevant to the question, " - "your answer must include the sentence 'The answer you are looking for is not found in the knowledge base!' " - "Answers need to consider chat history.\nHere is the knowledge base:\n{knowledge}\nThe above is the knowledge base." + "You are an intelligent assistant. Your primary function is to answer questions based strictly on the provided knowledge base." + "**Essential Rules:**" + "- Your answer must be derived **solely** from this knowledge base: `{knowledge}`." + "- **When information is available**: Summarize the content to give a detailed answer." + "- **When information is unavailable**: Your response must contain this exact sentence: 'The answer you are looking for is not found in the knowledge base!' " + "- **Always consider** the entire conversation history." ) temp_dict = {"name": name, "avatar": avatar, "dataset_ids": dataset_list if dataset_list else [], "llm": llm.to_json(), "prompt": prompt.to_json()} diff --git a/web/src/locales/en.ts b/web/src/locales/en.ts index 6e2e181443..9329c2c61a 100644 --- a/web/src/locales/en.ts +++ b/web/src/locales/en.ts @@ -647,10 +647,13 @@ This auto-tagging feature enhances retrieval by adding another layer of domain-s knowledgeBasesTip: 'Select the datasets to associate with this chat assistant. An empty knowledge base will not appear in the dropdown list.', system: 'System prompt', - systemInitialValue: `You are an intelligent assistant. Please summarize the content of the knowledge base to answer the question. Please list the data in the knowledge base and answer in detail. When all knowledge base content is irrelevant to the question, your answer must include the sentence "The answer you are looking for is not found in the knowledge base!" Answers need to consider chat history. - Here is the knowledge base: - {knowledge} - The above is the knowledge base.`, + systemInitialValue: `You are an intelligent assistant. Your primary function is to answer questions based strictly on the provided knowledge base. + + **Essential Rules:** + - Your answer must be derived **solely** from this knowledge base: \`{knowledge}\`. + - **When information is available**: Summarize the content to give a detailed answer. + - **When information is unavailable**: Your response must contain this exact sentence: "The answer you are looking for is not found in the knowledge base!" + - **Always consider** the entire conversation history.`, systemMessage: 'Please input!', systemTip: 'Your prompts or instructions for the LLM, including but not limited to its role, the desired length, tone, and language of its answers. If your model has native support for reasoning, you can add //no_thinking add the prompt to stop reasoning.',