- 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
63 lines
2.0 KiB
Python
63 lines
2.0 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
最小化测试脚本:测试 LLMClient 的输入输出
|
|
完全模拟真实调用路径,排除 Translator/TextProcessor 的干扰
|
|
"""
|
|
import sys
|
|
import asyncio
|
|
import json
|
|
import logging
|
|
from loguru import logger
|
|
from src.llm_client import LLMClient
|
|
from src.manifest_manager import ManifestItem
|
|
from src.utils import load_config
|
|
|
|
# 配置日志输出到控制台
|
|
logger.remove()
|
|
logger.add(sys.stdout, level="DEBUG")
|
|
|
|
async def test_io():
|
|
print("=== 初始化 LLMClient ===")
|
|
config = load_config()
|
|
# 使用 v3 provider
|
|
if 'v3' in config['providers']:
|
|
config['llm'] = config['providers']['v3']
|
|
print(f"Using provider: v3 (model: {config['llm']['models']['fast']})")
|
|
|
|
client = LLMClient(config)
|
|
|
|
# 构造测试 Item (模拟真实数据)
|
|
item = ManifestItem(
|
|
global_id="p_00006",
|
|
source_file="test.html",
|
|
original_html="<p>in the name of <span id='page_vi'></span> abundance...</p>",
|
|
clean_text="in the name of abundance...",
|
|
text_hash="dummy_hash",
|
|
tag="p",
|
|
# 关键:设置 text_with_placeholders
|
|
text_with_placeholders="in the name of φ1φabundance...", # 故意不加空格,模拟原始数据
|
|
placeholder_map={"1": "<span id='page_vi'></span>"},
|
|
paragraph_type="BODY"
|
|
)
|
|
|
|
items = [item]
|
|
mode = "chinese"
|
|
|
|
print("\n=== 1. 测试 _build_prompt 输出 ===")
|
|
# 直接调用私有方法查看生成的 prompt
|
|
prompt = client._build_prompt(items, mode=mode)
|
|
print(f"Generated Prompt:\n{prompt}")
|
|
print(f"Contains φ1φ: {'φ1φ' in prompt}")
|
|
|
|
print("\n=== 2. 测试 translate_chunk 完整调用 ===")
|
|
# 这会触发我们之前添加的 ERROR/DEBUG 日志
|
|
results = await client.translate_chunk(items, mode=mode)
|
|
|
|
print("\n=== 3. 检查结果 ===")
|
|
trans = results.get("p_00006", "MISSING")
|
|
print(f"Translation: {trans}")
|
|
print(f"Contains φ: {'φ' in trans}")
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(test_io())
|