From 5c7ced30df28ebf34252c1adbe2a106eedcdf74e Mon Sep 17 00:00:00 2001 From: carry <2641257231@qq.com> Date: Wed, 9 Apr 2025 10:26:14 +0800 Subject: [PATCH] =?UTF-8?q?fix(db):=20=E4=BF=AE=E5=A4=8D=20prompt=5Fstore?= =?UTF-8?q?=20=E5=88=9D=E5=A7=8B=E5=8C=96=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在插入默认模板之前检查数据库是否为空,如果数据库已有数据,则跳过插入默认模板 --- db/prompt_store.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/db/prompt_store.py b/db/prompt_store.py index 0db2e6a..c5cd057 100644 --- a/db/prompt_store.py +++ b/db/prompt_store.py @@ -41,13 +41,15 @@ def initialize_prompt_store(db: TinyDB) -> None: Args: db (TinyDB): TinyDB数据库实例 """ - db.insert(promptTempleta(name="default", - description="默认提示词模板", - content="""项目名为:{ project_name } + # 检查数据库是否为空 + if not db.all(): # 如果数据库中没有数据 + db.insert(promptTempleta(name="default", + description="默认提示词模板", + content="""项目名为:{ project_name } 请依据以下该项目官方文档的部分内容,创造合适的对话数据集用于微调一个了解该项目的小模型的语料,要求兼顾文档中间尽可能多的信息点,使用中文 文档节选:{ content } - 按照如下json格式返回:{ json }""").model_dump()) - # TinyDB不需要显式创建表结构,首次使用时自动创建 + 按照如下json格式返回:{ json }""").model_dump()) + # 如果数据库中已有数据,则跳过插入 if __name__ == "__main__":