feat: Release v0.10 - Modular Architecture & External Config
- Refactor codebase into src/ (preprocessing, translation, assembly) - Add pipeline/ scripts for individual stages - Externalize configuration to config/config.yaml - Fix Cover Image preservation - Update documentation and manuals
This commit is contained in:
@@ -0,0 +1,120 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
调试脚本:使用真实数据验证 Prompt 构建
|
||||
完整展示发送给 LLM 的文本
|
||||
"""
|
||||
import sys
|
||||
import json
|
||||
from pathlib import Path
|
||||
from loguru import logger
|
||||
|
||||
# 添加 src 到路径
|
||||
sys.path.insert(0, '.')
|
||||
|
||||
from src.manifest_manager import ManifestManager
|
||||
from src.text_processor import TextProcessor
|
||||
from src.llm_client import LLMClient
|
||||
from src.utils import load_config
|
||||
|
||||
# 配置日志到文件,避免控制台刷屏
|
||||
logger.remove()
|
||||
logger.add("debug_prompt.log", level="DEBUG")
|
||||
logger.add(sys.stdout, level="INFO")
|
||||
|
||||
def debug_prompt():
|
||||
print("=== 1. 加载配置 ===")
|
||||
try:
|
||||
config = load_config()
|
||||
# 确保 LLM 配置存在 (Mock if needed for init)
|
||||
if 'llm' not in config:
|
||||
if 'v3' in config['providers']:
|
||||
config['llm'] = config['providers']['v3']
|
||||
else:
|
||||
config['llm'] = {"api_key": "dummy", "models": {"fast": "dummy"}}
|
||||
|
||||
except Exception as e:
|
||||
print(f"Config load failed: {e}")
|
||||
return
|
||||
|
||||
print("=== 2. 加载真实 Manifest ===")
|
||||
# 查找 cache/manifests 下的 json 文件
|
||||
manifest_dir = Path("cache/manifests")
|
||||
if not manifest_dir.exists():
|
||||
print("Error: cache/manifests directory not found")
|
||||
return
|
||||
|
||||
manifest_files = list(manifest_dir.glob("*_manifest.json"))
|
||||
if not manifest_files:
|
||||
print("Error: No manifest file found in cache/manifests")
|
||||
return
|
||||
|
||||
manifest_path = manifest_files[0]
|
||||
print(f"Using manifest: {manifest_path}")
|
||||
|
||||
manifest = ManifestManager(str(manifest_path))
|
||||
if not manifest.load():
|
||||
print("Failed to load manifest")
|
||||
return
|
||||
|
||||
print(f"Loaded {len(manifest.get_items())} items")
|
||||
|
||||
# 获取 Pending items (模拟真实流程)
|
||||
pending = manifest.get_items(status="pending")
|
||||
if not pending:
|
||||
print("No pending items found. Using ALL items for debug.")
|
||||
items_to_process = manifest.get_items()
|
||||
else:
|
||||
items_to_process = pending
|
||||
|
||||
# 找到几个包含占位符的 item 用于验证
|
||||
target_items = []
|
||||
for item in items_to_process:
|
||||
if item.placeholder_map and len(item.placeholder_map) > 0:
|
||||
target_items.append(item)
|
||||
if len(target_items) >= 5: # 取前5个
|
||||
break
|
||||
|
||||
if not target_items:
|
||||
print("No items with placeholders found!")
|
||||
return
|
||||
|
||||
print(f"Selected {len(target_items)} items with placeholders for verification")
|
||||
for item in target_items:
|
||||
print(f" - {item.global_id}: twp length={len(item.text_with_placeholders or '')}")
|
||||
|
||||
print("\n=== 3. 生成 Prompt (Mode: Chinese) ===")
|
||||
client = LLMClient(config)
|
||||
|
||||
# 只为这几个 item 生成 prompt
|
||||
prompt = client._build_prompt(target_items, mode="chinese")
|
||||
|
||||
print("\n" + "="*40)
|
||||
print("FULL PROMPT CONTENT (Snippet):")
|
||||
print("="*40)
|
||||
print(prompt)
|
||||
print("="*40 + "\n")
|
||||
|
||||
print("\n=== 4. 关键验证 ===")
|
||||
placeholders_found = prompt.count('φ')
|
||||
print(f"Total 'φ' symbols in prompt: {placeholders_found}")
|
||||
|
||||
for item in target_items:
|
||||
if item.text_with_placeholders and 'φ' in item.text_with_placeholders:
|
||||
# 检查这个 item 的 ID 是否在 prompt 中
|
||||
in_prompt = item.global_id in prompt
|
||||
# 检查这个 item 的占位符是否在 prompt 中
|
||||
# 注意:如果占位符是 φ1φ,我们检查 'φ1φ' 是否在 prompt 中
|
||||
# 这里简单做,假设 text_with_placeholders 应该完整出现在 prompt 中 (忽略空白差异)
|
||||
import re
|
||||
normalized_twp = re.sub(r'\s+', '', item.text_with_placeholders)
|
||||
normalized_prompt = re.sub(r'\s+', '', prompt)
|
||||
|
||||
content_in_prompt = normalized_twp in normalized_prompt
|
||||
|
||||
print(f"Item {item.global_id}:")
|
||||
print(f" In prompt ID: {in_prompt}")
|
||||
print(f" Original twp: {repr(item.text_with_placeholders)}")
|
||||
print(f" Content match (ignoring whitespace): {content_in_prompt}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
debug_prompt()
|
||||
Reference in New Issue
Block a user