Skip to content

Commit 29fea0c

Browse files
committed
feat: translate Chinese to English in backend (critical LLM prompts)
- Translated all LLM prompt templates in report_agent.py (PLAN_*, SECTION_*, TOOL_DESC_*, REACT_*, CHAT_*) - Translated persona generation prompts in oasis_profile_generator.py (individual + group) - Translated ~600 strings across 34 backend Python files - Covers: prompts, tool descriptions, ReACT messages, docstrings, comments, log messages - ~3400 lines still have Chinese (comments/docs/logs) - tracked in GitHub issue - Reports and agent profiles now generate in English
1 parent 0f221ad commit 29fea0c

32 files changed

Lines changed: 1124 additions & 1124 deletions

backend/app/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
NemoFish Backend - Flask应用工厂
2+
NemoFish Backend - Flask Application Factory
33
"""
44

55
import os
@@ -17,7 +17,7 @@
1717

1818

1919
def create_app(config_class=Config):
20-
"""Flask应用工厂函数"""
20+
"""Flask application factory"""
2121
app = Flask(__name__)
2222
app.config.from_object(config_class)
2323

@@ -26,7 +26,7 @@ def create_app(config_class=Config):
2626
if hasattr(app, 'json') and hasattr(app.json, 'ensure_ascii'):
2727
app.json.ensure_ascii = False
2828

29-
# 设置日志
29+
# Set up logging
3030
logger = setup_logger('nemofish')
3131

3232
# 只在 reloader 子进程中打印启动信息(避免 debug 模式下打印两次)

backend/app/api/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
API路由模块
2+
API route modules
33
"""
44

55
from flask import Blueprint

backend/app/api/graph.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def delete_project(project_id: str):
8888
@graph_bp.route('/project/<project_id>/reset', methods=['POST'])
8989
def reset_project(project_id: str):
9090
"""
91-
重置项目状态(用于重新构建图谱)
91+
重置Project status(用于重新构建图谱)
9292
"""
9393
project = ProjectManager.get_project(project_id)
9494

@@ -287,10 +287,10 @@ def build_graph():
287287
if not Config.ZEP_API_KEY:
288288
errors.append("ZEP_API_KEY未配置")
289289
if errors:
290-
logger.error(f"配置错误: {errors}")
290+
logger.error(f"Configuration error: {errors}")
291291
return jsonify({
292292
"success": False,
293-
"error": "配置错误: " + "; ".join(errors)
293+
"error": "Configuration error: " + "; ".join(errors)
294294
}), 500
295295

296296
# 解析请求
@@ -312,7 +312,7 @@ def build_graph():
312312
"error": f"项目不存在: {project_id}"
313313
}), 404
314314

315-
# 检查项目状态
315+
# 检查Project status
316316
force = data.get('force', False) # 强制重新构建
317317

318318
if project.status == ProjectStatus.CREATED:
@@ -365,7 +365,7 @@ def build_graph():
365365
task_id = task_manager.create_task(f"构建图谱: {graph_name}")
366366
logger.info(f"创建图谱构建任务: task_id={task_id}, project_id={project_id}")
367367

368-
# 更新项目状态
368+
# 更新Project status
369369
project.status = ProjectStatus.GRAPH_BUILDING
370370
project.graph_build_task_id = task_id
371371
ProjectManager.save_project(project)
@@ -378,10 +378,10 @@ def build_task():
378378
task_manager.update_task(
379379
task_id,
380380
status=TaskStatus.PROCESSING,
381-
message="初始化图谱构建服务..."
381+
message="初始化Graph building service..."
382382
)
383383

384-
# 创建图谱构建服务
384+
# 创建Graph building service
385385
builder = GraphBuilderService(api_key=Config.ZEP_API_KEY)
386386

387387
# 分块
@@ -464,7 +464,7 @@ def wait_progress_callback(msg, progress_ratio):
464464
)
465465
graph_data = builder.get_graph_data(graph_id)
466466

467-
# 更新项目状态
467+
# 更新Project status
468468
project.status = ProjectStatus.GRAPH_COMPLETED
469469
ProjectManager.save_project(project)
470470

@@ -488,7 +488,7 @@ def wait_progress_callback(msg, progress_ratio):
488488
)
489489

490490
except Exception as e:
491-
# 更新项目状态为失败
491+
# 更新Project status为失败
492492
build_logger.error(f"[{task_id}] 图谱构建失败: {str(e)}")
493493
build_logger.debug(traceback.format_exc())
494494

backend/app/api/simulation.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ def prepare_simulation():
372372
1. 检查是否已有完成的准备工作
373373
2. 从Zep图谱读取并过滤实体
374374
3. 为每个实体生成OASIS Agent Profile(带重试机制)
375-
4. LLM智能生成模拟配置(带重试机制)
375+
4. LLM智能生成Simulation configuration(带重试机制)
376376
5. 保存配置文件和预设脚本
377377
378378
请求(JSON):
@@ -484,7 +484,7 @@ def prepare_simulation():
484484
logger.info(f"预期实体数量: {filtered_preview.filtered_count}, 类型: {filtered_preview.entity_types}")
485485
except Exception as e:
486486
logger.warning(f"同步获取实体数量失败(将在后台任务中重试): {e}")
487-
# 失败不影响后续流程,后台任务会重新获取
487+
# Failed不影响后续流程,后台任务会重新获取
488488

489489
# 创建异步任务
490490
task_manager = TaskManager()
@@ -530,7 +530,7 @@ def progress_callback(stage, progress, message, **kwargs):
530530
stage_names = {
531531
"reading": "读取图谱实体",
532532
"generating_profiles": "生成Agent人设",
533-
"generating_config": "生成模拟配置",
533+
"generating_config": "生成Simulation configuration",
534534
"copying_scripts": "准备模拟脚本"
535535
}
536536

@@ -749,7 +749,7 @@ def get_prepare_status():
749749

750750
@simulation_bp.route('/<simulation_id>', methods=['GET'])
751751
def get_simulation(simulation_id: str):
752-
"""获取模拟状态"""
752+
"""Get simulation status"""
753753
try:
754754
manager = SimulationManager()
755755
state = manager.get_simulation(simulation_id)
@@ -772,7 +772,7 @@ def get_simulation(simulation_id: str):
772772
})
773773

774774
except Exception as e:
775-
logger.error(f"获取模拟状态失败: {str(e)}")
775+
logger.error(f"Get simulation status失败: {str(e)}")
776776
return jsonify({
777777
"success": False,
778778
"error": str(e),
@@ -914,7 +914,7 @@ def get_simulation_history():
914914
for sim in simulations:
915915
sim_dict = sim.to_dict()
916916

917-
# 获取模拟配置信息(从 simulation_config.json 读取 simulation_requirement)
917+
# 获取Simulation configuration信息(从 simulation_config.json 读取 simulation_requirement)
918918
config = manager.get_simulation_config(sim.simulation_id)
919919
if config:
920920
sim_dict["simulation_requirement"] = config.get("simulation_requirement", "")
@@ -1133,7 +1133,7 @@ def get_simulation_profiles_realtime(simulation_id: str):
11331133
@simulation_bp.route('/<simulation_id>/config/realtime', methods=['GET'])
11341134
def get_simulation_config_realtime(simulation_id: str):
11351135
"""
1136-
实时获取模拟配置(用于在生成过程中实时查看进度)
1136+
实时获取Simulation configuration(用于在生成过程中实时查看进度)
11371137
11381138
与 /config 接口的区别:
11391139
- 直接读取文件,不经过 SimulationManager
@@ -1253,7 +1253,7 @@ def get_simulation_config_realtime(simulation_id: str):
12531253
@simulation_bp.route('/<simulation_id>/config', methods=['GET'])
12541254
def get_simulation_config(simulation_id: str):
12551255
"""
1256-
获取模拟配置(LLM智能生成的完整配置)
1256+
获取Simulation configuration(LLM智能生成的完整配置)
12571257
12581258
返回包含:
12591259
- time_config: 时间配置(模拟时长、轮次、高峰/低谷时段)
@@ -1269,7 +1269,7 @@ def get_simulation_config(simulation_id: str):
12691269
if not config:
12701270
return jsonify({
12711271
"success": False,
1272-
"error": f"模拟配置不存在,请先调用 /prepare 接口"
1272+
"error": f"Simulation configuration不存在,请先调用 /prepare 接口"
12731273
}), 404
12741274

12751275
return jsonify({
@@ -1288,7 +1288,7 @@ def get_simulation_config(simulation_id: str):
12881288

12891289
@simulation_bp.route('/<simulation_id>/config/download', methods=['GET'])
12901290
def download_simulation_config(simulation_id: str):
1291-
"""下载模拟配置文件"""
1291+
"""下载Simulation configuration文件"""
12921292
try:
12931293
manager = SimulationManager()
12941294
sim_dir = manager._get_simulation_dir(simulation_id)
@@ -1550,7 +1550,7 @@ def start_simulation():
15501550
try:
15511551
SimulationRunner.stop_simulation(simulation_id)
15521552
except Exception as e:
1553-
logger.warning(f"停止模拟时出现警告: {str(e)}")
1553+
logger.warning(f"Stop simulation时出现警告: {str(e)}")
15541554
else:
15551555
return jsonify({
15561556
"success": False,
@@ -1595,7 +1595,7 @@ def start_simulation():
15951595

15961596
logger.info(f"启用图谱记忆更新: simulation_id={simulation_id}, graph_id={graph_id}")
15971597

1598-
# 启动模拟
1598+
# Start simulation
15991599
run_state = SimulationRunner.start_simulation(
16001600
simulation_id=simulation_id,
16011601
platform=platform,
@@ -1628,7 +1628,7 @@ def start_simulation():
16281628
}), 400
16291629

16301630
except Exception as e:
1631-
logger.error(f"启动模拟失败: {str(e)}")
1631+
logger.error(f"Start simulation失败: {str(e)}")
16321632
return jsonify({
16331633
"success": False,
16341634
"error": str(e),
@@ -1639,7 +1639,7 @@ def start_simulation():
16391639
@simulation_bp.route('/stop', methods=['POST'])
16401640
def stop_simulation():
16411641
"""
1642-
停止模拟
1642+
Stop simulation
16431643
16441644
请求(JSON):
16451645
{
@@ -1687,7 +1687,7 @@ def stop_simulation():
16871687
}), 400
16881688

16891689
except Exception as e:
1690-
logger.error(f"停止模拟失败: {str(e)}")
1690+
logger.error(f"Stop simulation失败: {str(e)}")
16911691
return jsonify({
16921692
"success": False,
16931693
"error": str(e),

backend/app/config.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""
2-
配置管理
3-
统一从项目根目录的 .env 文件加载配置
2+
Configuration management
3+
Load config from project root .env file
44
"""
55

66
import os
@@ -18,9 +18,9 @@
1818

1919

2020
class Config:
21-
"""Flask配置类"""
21+
"""Flask configuration class"""
2222

23-
# Flask配置
23+
# Flask configuration
2424
SECRET_KEY = os.environ.get('SECRET_KEY', 'nemofish-secret-key')
2525
DEBUG = os.environ.get('FLASK_DEBUG', 'True').lower() == 'true'
2626

@@ -41,10 +41,10 @@ class Config:
4141
ALLOWED_EXTENSIONS = {'pdf', 'md', 'txt', 'markdown'}
4242

4343
# 文本处理配置
44-
DEFAULT_CHUNK_SIZE = 500 # 默认切块大小
45-
DEFAULT_CHUNK_OVERLAP = 50 # 默认重叠大小
44+
DEFAULT_CHUNK_SIZE = 500 # 默认切Chunk size
45+
DEFAULT_CHUNK_OVERLAP = 50 # 默认Overlap size
4646

47-
# OASIS模拟配置
47+
# OASISSimulation configuration
4848
OASIS_DEFAULT_MAX_ROUNDS = int(os.environ.get('OASIS_DEFAULT_MAX_ROUNDS', '10'))
4949
OASIS_SIMULATION_DATA_DIR = os.path.join(os.path.dirname(__file__), '../uploads/simulations')
5050

@@ -68,8 +68,8 @@ def validate(cls):
6868
"""验证必要配置"""
6969
errors = []
7070
if not cls.LLM_API_KEY:
71-
errors.append("LLM_API_KEY 未配置")
71+
errors.append("LLM_API_KEY not configured")
7272
if not cls.ZEP_API_KEY:
73-
errors.append("ZEP_API_KEY 未配置")
73+
errors.append("ZEP_API_KEY not configured")
7474
return errors
7575

backend/app/models/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
数据模型模块
2+
Data model modules
33
"""
44

55
from .task import TaskManager, TaskStatus

backend/app/models/project.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""
2-
项目上下文管理
3-
用于在服务端持久化项目状态,避免前端在接口间传递大量数据
2+
Project context management
3+
Server-side project state persistence
44
"""
55

66
import os
@@ -15,12 +15,12 @@
1515

1616

1717
class ProjectStatus(str, Enum):
18-
"""项目状态"""
19-
CREATED = "created" # 刚创建,文件已上传
20-
ONTOLOGY_GENERATED = "ontology_generated" # 本体已生成
21-
GRAPH_BUILDING = "graph_building" # 图谱构建中
22-
GRAPH_COMPLETED = "graph_completed" # 图谱构建完成
23-
FAILED = "failed" # 失败
18+
"""Project status"""
19+
CREATED = "created" # Just created, file uploaded
20+
ONTOLOGY_GENERATED = "ontology_generated" # Ontology generated
21+
GRAPH_BUILDING = "graph_building" # Graph building
22+
GRAPH_COMPLETED = "graph_completed" # Graph completed
23+
FAILED = "failed" # Failed
2424

2525

2626
@dataclass
@@ -40,7 +40,7 @@ class Project:
4040
ontology: Optional[Dict[str, Any]] = None
4141
analysis_summary: Optional[str] = None
4242

43-
# 图谱信息(接口2完成后填充)
43+
# Graph information(接口2完成后填充)
4444
graph_id: Optional[str] = None
4545
graph_build_task_id: Optional[str] = None
4646

@@ -49,11 +49,11 @@ class Project:
4949
chunk_size: int = 500
5050
chunk_overlap: int = 50
5151

52-
# 错误信息
52+
# Error info
5353
error: Optional[str] = None
5454

5555
def to_dict(self) -> Dict[str, Any]:
56-
"""转换为字典"""
56+
"""Convert to dictionary"""
5757
return {
5858
"project_id": self.project_id,
5959
"name": self.name,

backend/app/models/task.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""
2-
任务状态管理
3-
用于跟踪长时间运行的任务(如图谱构建)
2+
Task status management
3+
For tracking long-running tasks (e.g. graph building)
44
"""
55

66
import uuid
@@ -12,16 +12,16 @@
1212

1313

1414
class TaskStatus(str, Enum):
15-
"""任务状态枚举"""
16-
PENDING = "pending" # 等待中
17-
PROCESSING = "processing" # 处理中
18-
COMPLETED = "completed" # 已完成
19-
FAILED = "failed" # 失败
15+
"""Task status enum"""
16+
PENDING = "pending" # Pending
17+
PROCESSING = "processing" # Processing
18+
COMPLETED = "completed" # Completed
19+
FAILED = "failed" # Failed
2020

2121

2222
@dataclass
2323
class Task:
24-
"""任务数据类"""
24+
"""Task data class"""
2525
task_id: str
2626
task_type: str
2727
status: TaskStatus
@@ -30,12 +30,12 @@ class Task:
3030
progress: int = 0 # 总进度百分比 0-100
3131
message: str = "" # 状态消息
3232
result: Optional[Dict] = None # 任务结果
33-
error: Optional[str] = None # 错误信息
33+
error: Optional[str] = None # Error info
3434
metadata: Dict = field(default_factory=dict) # 额外元数据
3535
progress_detail: Dict = field(default_factory=dict) # 详细进度信息
3636

3737
def to_dict(self) -> Dict[str, Any]:
38-
"""转换为字典"""
38+
"""Convert to dictionary"""
3939
return {
4040
"task_id": self.task_id,
4141
"task_type": self.task_type,
@@ -54,7 +54,7 @@ def to_dict(self) -> Dict[str, Any]:
5454
class TaskManager:
5555
"""
5656
任务管理器
57-
线程安全的任务状态管理
57+
线程安全的Task status management
5858
"""
5959

6060
_instance = None

0 commit comments

Comments
 (0)