From 7df1bd4b4a791640c6ed4f547a7433bc8cc9d7f7 Mon Sep 17 00:00:00 2001 From: liwenju0 Date: Mon, 19 May 2025 11:33:54 +0800 Subject: [PATCH] When creating an assistant, no dataset is specified, a different default system promt is used (#7690) ### What problem does this PR solve? - Updated the dialog settings function to add a default prompt configuration for no dataset. - The prompt configuration will be determined based on the presence of `kb_ids` in the request. ### Type of change - [ ] Bug Fix (non-breaking change which fixes an issue) - [x] New Feature (Non-breaking change, adding functionality) - [ ] Documentation Update - [ ] Refactoring - [ ] Performance Improvement - [ ] Other (please describe): --------- Co-authored-by: wenju.li --- api/apps/dialog_app.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/api/apps/dialog_app.py b/api/apps/dialog_app.py index 42fde4f9f..4878e0732 100644 --- a/api/apps/dialog_app.py +++ b/api/apps/dialog_app.py @@ -43,7 +43,7 @@ def set_dialog(): similarity_threshold = req.get("similarity_threshold", 0.1) vector_similarity_weight = req.get("vector_similarity_weight", 0.3) llm_setting = req.get("llm_setting", {}) - default_prompt = { + default_prompt_with_dataset = { "system": """你是一个智能助手,请总结知识库的内容来回答问题,请列举知识库中的数据详细回答。当所有知识库内容都与问题无关时,你的回答必须包括“知识库中未找到您要的答案!”这句话。回答需要考虑聊天历史。 以下是知识库: {knowledge} @@ -54,10 +54,22 @@ def set_dialog(): ], "empty_response": "Sorry! 知识库中未找到相关内容!" } - prompt_config = req.get("prompt_config", default_prompt) + default_prompt_no_dataset = { + "system": """You are a helpful assistant.""", + "prologue": "您好,我是您的助手小樱,长得可爱又善良,can I help you?", + "parameters": [ + + ], + "empty_response": "" + } + prompt_config = req.get("prompt_config", default_prompt_with_dataset) if not prompt_config["system"]: - prompt_config["system"] = default_prompt["system"] + prompt_config["system"] = default_prompt_with_dataset["system"] + + if not req.get("kb_ids", []): + if prompt_config['system'] == default_prompt_with_dataset['system'] or "{knowledge}" in prompt_config['system']: + prompt_config = default_prompt_no_dataset for p in prompt_config["parameters"]: if p["optional"]: