From 1057727fc5c35890c45aed10c8e37c171b0047dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E9=B1=BC=E5=BC=80=E5=8F=91?= Date: Wed, 22 Apr 2026 11:10:33 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E7=BB=9F=E4=B8=80=20system/=5Fmeta?= =?UTF-8?q?.json=20=E7=AE=A1=E7=90=86=E5=88=86=E7=B1=BB=EF=BC=9B=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E5=89=8D=E7=AB=AF=20TypeScript=20=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- python-api/app/ai/prompts/loader.py | 48 +++++++++++-------- python-api/app/ai/prompts/system/_meta.json | 13 +++++ .../app/ai/prompts/system/bk/ht/_meta.json | 1 - .../app/ai/prompts/system/bk/lc/_meta.json | 1 - .../app/ai/prompts/system/bk/qw/_meta.json | 1 - .../pages/VideoCreation/ScriptCreation.tsx | 1 - .../src/pages/VideoCreation/VoiceDubbing.tsx | 4 +- tauri-app/src/store/projectStore.ts | 3 ++ 8 files changed, 45 insertions(+), 27 deletions(-) create mode 100644 python-api/app/ai/prompts/system/_meta.json delete mode 100644 python-api/app/ai/prompts/system/bk/ht/_meta.json delete mode 100644 python-api/app/ai/prompts/system/bk/lc/_meta.json delete mode 100644 python-api/app/ai/prompts/system/bk/qw/_meta.json diff --git a/python-api/app/ai/prompts/loader.py b/python-api/app/ai/prompts/loader.py index 5aa68d0..2c36fb3 100644 --- a/python-api/app/ai/prompts/loader.py +++ b/python-api/app/ai/prompts/loader.py @@ -14,6 +14,7 @@ Prompt 简单加载器 └── ... """ +import json import json import random from pathlib import Path @@ -60,12 +61,25 @@ def render_template(template: str, **kwargs) -> str: # ====================== 新分类体系:动态扫描 ====================== SYSTEM_PROMPTS_DIR = _PROMPTS_DIR / "system" +_SYSTEM_META_PATH = SYSTEM_PROMPTS_DIR / "_meta.json" + + +def _load_system_meta() -> dict: + """读取 system/_meta.json""" + if _SYSTEM_META_PATH.exists(): + try: + return json.loads(_SYSTEM_META_PATH.read_text(encoding="utf-8")) + except (json.JSONDecodeError, OSError): + pass + return {} def list_categories() -> list[dict]: """ 扫描 system/ 目录,返回所有分类结构 + 名称从 system/_meta.json 读取,count 动态扫描目录统计。 + Returns: [ { @@ -79,7 +93,10 @@ def list_categories() -> list[dict]: ... ] """ + meta = _load_system_meta() + meta_categories = {c["code"]: c for c in meta.get("categories", [])} categories = [] + if not SYSTEM_PROMPTS_DIR.exists(): return categories @@ -87,34 +104,34 @@ def list_categories() -> list[dict]: if not cat_dir.is_dir(): continue - # 读取大类元数据 - cat_meta = _load_meta(cat_dir) - cat_name = cat_meta.get("name", cat_dir.name) + cat_code = cat_dir.name + cat_meta = meta_categories.get(cat_code, {}) + meta_subs = {s["code"]: s for s in cat_meta.get("subcategories", [])} + cat_name = cat_meta.get("name", cat_code) subcategories = [] for sub_dir in sorted(cat_dir.iterdir()): if not sub_dir.is_dir(): continue - # 读取小类元数据 - sub_meta = _load_meta(sub_dir) - sub_name = sub_meta.get("name", sub_dir.name) + sub_code = sub_dir.name + sub_name = meta_subs.get(sub_code, {}).get("name", sub_code) # 统计提示词文件数量(排除 _meta.json) prompt_files = [ f for f in sub_dir.iterdir() - if f.is_file() and f.name != "_meta.json" + if f.is_file() and f.suffix == ".txt" ] subcategories.append({ - "code": sub_dir.name, + "code": sub_code, "name": sub_name, "count": len(prompt_files), }) if subcategories: categories.append({ - "code": cat_dir.name, + "code": cat_code, "name": cat_name, "subcategories": subcategories, }) @@ -122,17 +139,6 @@ def list_categories() -> list[dict]: return categories -def _load_meta(directory: Path) -> dict: - """读取目录下的 _meta.json""" - meta_path = directory / "_meta.json" - if meta_path.exists(): - try: - return json.loads(meta_path.read_text(encoding="utf-8")) - except (json.JSONDecodeError, OSError): - pass - return {} - - def load_system_prompt(category: str, subcategory: str) -> str: """ 根据大类+小类随机加载一个 System Prompt @@ -148,7 +154,7 @@ def load_system_prompt(category: str, subcategory: str) -> str: if not sub_dir.exists(): return "" - # 收集所有提示词文件(排除 _meta.json) + # 收集所有提示词文件 prompt_files = [ f for f in sub_dir.iterdir() if f.is_file() and f.suffix == ".txt" diff --git a/python-api/app/ai/prompts/system/_meta.json b/python-api/app/ai/prompts/system/_meta.json new file mode 100644 index 0000000..0e3daa6 --- /dev/null +++ b/python-api/app/ai/prompts/system/_meta.json @@ -0,0 +1,13 @@ +{ + "categories": [ + { + "code": "bk", + "name": "装修避坑", + "subcategories": [ + { "code": "ht", "name": "装修合同避坑" }, + { "code": "lc", "name": "装修全流程避坑" }, + { "code": "qw", "name": "全屋定制避坑" } + ] + } + ] +} diff --git a/python-api/app/ai/prompts/system/bk/ht/_meta.json b/python-api/app/ai/prompts/system/bk/ht/_meta.json deleted file mode 100644 index f5f4d1a..0000000 --- a/python-api/app/ai/prompts/system/bk/ht/_meta.json +++ /dev/null @@ -1 +0,0 @@ -{"name": "装修合同避坑"} diff --git a/python-api/app/ai/prompts/system/bk/lc/_meta.json b/python-api/app/ai/prompts/system/bk/lc/_meta.json deleted file mode 100644 index 21d6bbd..0000000 --- a/python-api/app/ai/prompts/system/bk/lc/_meta.json +++ /dev/null @@ -1 +0,0 @@ -{"name": "装修全流程避坑"} diff --git a/python-api/app/ai/prompts/system/bk/qw/_meta.json b/python-api/app/ai/prompts/system/bk/qw/_meta.json deleted file mode 100644 index b0a265e..0000000 --- a/python-api/app/ai/prompts/system/bk/qw/_meta.json +++ /dev/null @@ -1 +0,0 @@ -{"name": "全屋定制避坑"} diff --git a/tauri-app/src/pages/VideoCreation/ScriptCreation.tsx b/tauri-app/src/pages/VideoCreation/ScriptCreation.tsx index 6bb3a90..567d16f 100644 --- a/tauri-app/src/pages/VideoCreation/ScriptCreation.tsx +++ b/tauri-app/src/pages/VideoCreation/ScriptCreation.tsx @@ -20,7 +20,6 @@ export default function ScriptCreation() { const segments = useProjectStore(state => state.segments); const setSegments = useProjectStore(state => state.setSegments); const updateSegment = useProjectStore(state => state.updateSegment); - const topic = useProjectStore(state => state.topic) || ''; const setTopic = useProjectStore(state => state.setTopic); const scriptDuration = useProjectStore(state => state.scriptDuration) || 45; const setScriptDuration = useProjectStore(state => state.setScriptDuration); diff --git a/tauri-app/src/pages/VideoCreation/VoiceDubbing.tsx b/tauri-app/src/pages/VideoCreation/VoiceDubbing.tsx index f390f2f..5ebe710 100644 --- a/tauri-app/src/pages/VideoCreation/VoiceDubbing.tsx +++ b/tauri-app/src/pages/VideoCreation/VoiceDubbing.tsx @@ -218,7 +218,7 @@ export default function VoiceDubbing() { {v.description} - @@ -243,7 +243,7 @@ export default function VoiceDubbing() { - diff --git a/tauri-app/src/store/projectStore.ts b/tauri-app/src/store/projectStore.ts index 4ff6283..81c2b73 100644 --- a/tauri-app/src/store/projectStore.ts +++ b/tauri-app/src/store/projectStore.ts @@ -88,6 +88,9 @@ interface SaveState { selectedHumanId?: string; selectedElementId?: number; selectedVoiceId?: string; + dubbingAudioUrl?: string; + dubbingAudioPath?: string; + dubbingVoiceId?: string; scriptDuration?: number; scriptType?: string; currentStep?: number;