feat(i18n): replace hardcoded Chinese in backend SSE progress messages
This commit is contained in:
@@ -379,7 +379,7 @@ def build_graph():
|
||||
task_manager.update_task(
|
||||
task_id,
|
||||
status=TaskStatus.PROCESSING,
|
||||
message="初始化图谱构建服务..."
|
||||
message=t('progress.initGraphService')
|
||||
)
|
||||
|
||||
# 创建图谱构建服务
|
||||
@@ -388,7 +388,7 @@ def build_graph():
|
||||
# 分块
|
||||
task_manager.update_task(
|
||||
task_id,
|
||||
message="文本分块中...",
|
||||
message=t('progress.textChunking'),
|
||||
progress=5
|
||||
)
|
||||
chunks = TextProcessor.split_text(
|
||||
@@ -401,7 +401,7 @@ def build_graph():
|
||||
# 创建图谱
|
||||
task_manager.update_task(
|
||||
task_id,
|
||||
message="创建Zep图谱...",
|
||||
message=t('progress.creatingZepGraph'),
|
||||
progress=10
|
||||
)
|
||||
graph_id = builder.create_graph(name=graph_name)
|
||||
@@ -413,7 +413,7 @@ def build_graph():
|
||||
# 设置本体
|
||||
task_manager.update_task(
|
||||
task_id,
|
||||
message="设置本体定义...",
|
||||
message=t('progress.settingOntology'),
|
||||
progress=15
|
||||
)
|
||||
builder.set_ontology(graph_id, ontology)
|
||||
@@ -429,7 +429,7 @@ def build_graph():
|
||||
|
||||
task_manager.update_task(
|
||||
task_id,
|
||||
message=f"开始添加 {total_chunks} 个文本块...",
|
||||
message=t('progress.addingChunks', count=total_chunks),
|
||||
progress=15
|
||||
)
|
||||
|
||||
@@ -443,7 +443,7 @@ def build_graph():
|
||||
# 等待Zep处理完成(查询每个episode的processed状态)
|
||||
task_manager.update_task(
|
||||
task_id,
|
||||
message="等待Zep处理数据...",
|
||||
message=t('progress.waitingZepProcess'),
|
||||
progress=55
|
||||
)
|
||||
|
||||
@@ -460,7 +460,7 @@ def build_graph():
|
||||
# 获取图谱数据
|
||||
task_manager.update_task(
|
||||
task_id,
|
||||
message="获取图谱数据...",
|
||||
message=t('progress.fetchingGraphData'),
|
||||
progress=95
|
||||
)
|
||||
graph_data = builder.get_graph_data(graph_id)
|
||||
@@ -477,7 +477,7 @@ def build_graph():
|
||||
task_manager.update_task(
|
||||
task_id,
|
||||
status=TaskStatus.COMPLETED,
|
||||
message="图谱构建完成",
|
||||
message=t('progress.graphBuildComplete'),
|
||||
progress=100,
|
||||
result={
|
||||
"project_id": project_id,
|
||||
@@ -500,7 +500,7 @@ def build_graph():
|
||||
task_manager.update_task(
|
||||
task_id,
|
||||
status=TaskStatus.FAILED,
|
||||
message=f"构建失败: {str(e)}",
|
||||
message=t('progress.buildFailed', error=str(e)),
|
||||
error=traceback.format_exc()
|
||||
)
|
||||
|
||||
|
||||
@@ -508,7 +508,7 @@ def prepare_simulation():
|
||||
task_id,
|
||||
status=TaskStatus.PROCESSING,
|
||||
progress=0,
|
||||
message="开始准备模拟环境..."
|
||||
message=t('progress.startPreparingEnv')
|
||||
)
|
||||
|
||||
# 准备模拟(带进度回调)
|
||||
|
||||
@@ -10,6 +10,8 @@ from enum import Enum
|
||||
from typing import Dict, Any, Optional
|
||||
from dataclasses import dataclass, field
|
||||
|
||||
from ..utils.locale import t
|
||||
|
||||
|
||||
class TaskStatus(str, Enum):
|
||||
"""任务状态枚举"""
|
||||
@@ -148,7 +150,7 @@ class TaskManager:
|
||||
task_id,
|
||||
status=TaskStatus.COMPLETED,
|
||||
progress=100,
|
||||
message="任务完成",
|
||||
message=t('progress.taskComplete'),
|
||||
result=result
|
||||
)
|
||||
|
||||
@@ -157,7 +159,7 @@ class TaskManager:
|
||||
self.update_task(
|
||||
task_id,
|
||||
status=TaskStatus.FAILED,
|
||||
message="任务失败",
|
||||
message=t('progress.taskFailed'),
|
||||
error=error
|
||||
)
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ from ..config import Config
|
||||
from ..models.task import TaskManager, TaskStatus
|
||||
from ..utils.zep_paging import fetch_all_nodes, fetch_all_edges
|
||||
from .text_processor import TextProcessor
|
||||
from ..utils.locale import t
|
||||
|
||||
|
||||
@dataclass
|
||||
@@ -109,7 +110,7 @@ class GraphBuilderService:
|
||||
task_id,
|
||||
status=TaskStatus.PROCESSING,
|
||||
progress=5,
|
||||
message="开始构建图谱..."
|
||||
message=t('progress.startBuildingGraph')
|
||||
)
|
||||
|
||||
# 1. 创建图谱
|
||||
@@ -117,7 +118,7 @@ class GraphBuilderService:
|
||||
self.task_manager.update_task(
|
||||
task_id,
|
||||
progress=10,
|
||||
message=f"图谱已创建: {graph_id}"
|
||||
message=t('progress.graphCreated', graphId=graph_id)
|
||||
)
|
||||
|
||||
# 2. 设置本体
|
||||
@@ -125,7 +126,7 @@ class GraphBuilderService:
|
||||
self.task_manager.update_task(
|
||||
task_id,
|
||||
progress=15,
|
||||
message="本体已设置"
|
||||
message=t('progress.ontologySet')
|
||||
)
|
||||
|
||||
# 3. 文本分块
|
||||
@@ -134,7 +135,7 @@ class GraphBuilderService:
|
||||
self.task_manager.update_task(
|
||||
task_id,
|
||||
progress=20,
|
||||
message=f"文本已分割为 {total_chunks} 个块"
|
||||
message=t('progress.textSplit', count=total_chunks)
|
||||
)
|
||||
|
||||
# 4. 分批发送数据
|
||||
@@ -151,7 +152,7 @@ class GraphBuilderService:
|
||||
self.task_manager.update_task(
|
||||
task_id,
|
||||
progress=60,
|
||||
message="等待Zep处理数据..."
|
||||
message=t('progress.waitingZepProcess')
|
||||
)
|
||||
|
||||
self._wait_for_episodes(
|
||||
@@ -167,7 +168,7 @@ class GraphBuilderService:
|
||||
self.task_manager.update_task(
|
||||
task_id,
|
||||
progress=90,
|
||||
message="获取图谱信息..."
|
||||
message=t('progress.fetchingGraphInfo')
|
||||
)
|
||||
|
||||
graph_info = self._get_graph_info(graph_id)
|
||||
@@ -304,7 +305,7 @@ class GraphBuilderService:
|
||||
if progress_callback:
|
||||
progress = (i + len(batch_chunks)) / total_chunks
|
||||
progress_callback(
|
||||
f"发送第 {batch_num}/{total_batches} 批数据 ({len(batch_chunks)} 块)...",
|
||||
t('progress.sendingBatch', current=batch_num, total=total_batches, chunks=len(batch_chunks)),
|
||||
progress
|
||||
)
|
||||
|
||||
@@ -333,7 +334,7 @@ class GraphBuilderService:
|
||||
|
||||
except Exception as e:
|
||||
if progress_callback:
|
||||
progress_callback(f"批次 {batch_num} 发送失败: {str(e)}", 0)
|
||||
progress_callback(t('progress.batchFailed', batch=batch_num, error=str(e)), 0)
|
||||
raise
|
||||
|
||||
return episode_uuids
|
||||
@@ -347,7 +348,7 @@ class GraphBuilderService:
|
||||
"""等待所有 episode 处理完成(通过查询每个 episode 的 processed 状态)"""
|
||||
if not episode_uuids:
|
||||
if progress_callback:
|
||||
progress_callback("无需等待(没有 episode)", 1.0)
|
||||
progress_callback(t('progress.noEpisodesWait'), 1.0)
|
||||
return
|
||||
|
||||
start_time = time.time()
|
||||
@@ -356,13 +357,13 @@ class GraphBuilderService:
|
||||
total_episodes = len(episode_uuids)
|
||||
|
||||
if progress_callback:
|
||||
progress_callback(f"开始等待 {total_episodes} 个文本块处理...", 0)
|
||||
progress_callback(t('progress.waitingEpisodes', count=total_episodes), 0)
|
||||
|
||||
while pending_episodes:
|
||||
if time.time() - start_time > timeout:
|
||||
if progress_callback:
|
||||
progress_callback(
|
||||
f"部分文本块超时,已完成 {completed_count}/{total_episodes}",
|
||||
t('progress.episodesTimeout', completed=completed_count, total=total_episodes),
|
||||
completed_count / total_episodes
|
||||
)
|
||||
break
|
||||
@@ -384,7 +385,7 @@ class GraphBuilderService:
|
||||
elapsed = int(time.time() - start_time)
|
||||
if progress_callback:
|
||||
progress_callback(
|
||||
f"Zep处理中... {completed_count}/{total_episodes} 完成, {len(pending_episodes)} 待处理 ({elapsed}秒)",
|
||||
t('progress.zepProcessing', completed=completed_count, total=total_episodes, pending=len(pending_episodes), elapsed=elapsed),
|
||||
completed_count / total_episodes if total_episodes > 0 else 0
|
||||
)
|
||||
|
||||
@@ -392,7 +393,7 @@ class GraphBuilderService:
|
||||
time.sleep(3) # 每3秒检查一次
|
||||
|
||||
if progress_callback:
|
||||
progress_callback(f"处理完成: {completed_count}/{total_episodes}", 1.0)
|
||||
progress_callback(t('progress.processingComplete', completed=completed_count, total=total_episodes), 1.0)
|
||||
|
||||
def _get_graph_info(self, graph_id: str) -> GraphInfo:
|
||||
"""获取图谱信息"""
|
||||
|
||||
@@ -21,7 +21,7 @@ from enum import Enum
|
||||
from ..config import Config
|
||||
from ..utils.llm_client import LLMClient
|
||||
from ..utils.logger import get_logger
|
||||
from ..utils.locale import get_language_instruction
|
||||
from ..utils.locale import get_language_instruction, t
|
||||
from .zep_tools import (
|
||||
ZepToolsService,
|
||||
SearchResult,
|
||||
@@ -1152,7 +1152,7 @@ class ReportAgent:
|
||||
logger.info("开始规划报告大纲...")
|
||||
|
||||
if progress_callback:
|
||||
progress_callback("planning", 0, "正在分析模拟需求...")
|
||||
progress_callback("planning", 0, t('progress.analyzingRequirements'))
|
||||
|
||||
# 首先获取模拟上下文
|
||||
context = self.zep_tools.get_simulation_context(
|
||||
@@ -1161,7 +1161,7 @@ class ReportAgent:
|
||||
)
|
||||
|
||||
if progress_callback:
|
||||
progress_callback("planning", 30, "正在生成报告大纲...")
|
||||
progress_callback("planning", 30, t('progress.generatingOutline'))
|
||||
|
||||
system_prompt = f"{PLAN_SYSTEM_PROMPT}\n\n{get_language_instruction()}"
|
||||
user_prompt = PLAN_USER_PROMPT_TEMPLATE.format(
|
||||
@@ -1183,7 +1183,7 @@ class ReportAgent:
|
||||
)
|
||||
|
||||
if progress_callback:
|
||||
progress_callback("planning", 80, "正在解析大纲结构...")
|
||||
progress_callback("planning", 80, t('progress.parsingOutline'))
|
||||
|
||||
# 解析大纲
|
||||
sections = []
|
||||
@@ -1200,7 +1200,7 @@ class ReportAgent:
|
||||
)
|
||||
|
||||
if progress_callback:
|
||||
progress_callback("planning", 100, "大纲规划完成")
|
||||
progress_callback("planning", 100, t('progress.outlinePlanComplete'))
|
||||
|
||||
logger.info(f"大纲规划完成: {len(sections)} 个章节")
|
||||
return outline
|
||||
@@ -1298,7 +1298,7 @@ class ReportAgent:
|
||||
progress_callback(
|
||||
"generating",
|
||||
int((iteration / max_iterations) * 100),
|
||||
f"深度检索与撰写中 ({tool_calls_count}/{self.MAX_TOOL_CALLS_PER_SECTION})"
|
||||
t('progress.deepSearchAndWrite', current=tool_calls_count, max=self.MAX_TOOL_CALLS_PER_SECTION)
|
||||
)
|
||||
|
||||
# 调用LLM
|
||||
@@ -1592,7 +1592,7 @@ class ReportAgent:
|
||||
self.console_logger = ReportConsoleLogger(report_id)
|
||||
|
||||
ReportManager.update_progress(
|
||||
report_id, "pending", 0, "初始化报告...",
|
||||
report_id, "pending", 0, t('progress.initReport'),
|
||||
completed_sections=[]
|
||||
)
|
||||
ReportManager.save_report(report)
|
||||
@@ -1600,7 +1600,7 @@ class ReportAgent:
|
||||
# 阶段1: 规划大纲
|
||||
report.status = ReportStatus.PLANNING
|
||||
ReportManager.update_progress(
|
||||
report_id, "planning", 5, "开始规划报告大纲...",
|
||||
report_id, "planning", 5, t('progress.startPlanningOutline'),
|
||||
completed_sections=[]
|
||||
)
|
||||
|
||||
@@ -1608,7 +1608,7 @@ class ReportAgent:
|
||||
self.report_logger.log_planning_start()
|
||||
|
||||
if progress_callback:
|
||||
progress_callback("planning", 0, "开始规划报告大纲...")
|
||||
progress_callback("planning", 0, t('progress.startPlanningOutline'))
|
||||
|
||||
outline = self.plan_outline(
|
||||
progress_callback=lambda stage, prog, msg:
|
||||
@@ -1622,7 +1622,7 @@ class ReportAgent:
|
||||
# 保存大纲到文件
|
||||
ReportManager.save_outline(report_id, outline)
|
||||
ReportManager.update_progress(
|
||||
report_id, "planning", 15, f"大纲规划完成,共{len(outline.sections)}个章节",
|
||||
report_id, "planning", 15, t('progress.outlineDone', count=len(outline.sections)),
|
||||
completed_sections=[]
|
||||
)
|
||||
ReportManager.save_report(report)
|
||||
@@ -1642,16 +1642,16 @@ class ReportAgent:
|
||||
# 更新进度
|
||||
ReportManager.update_progress(
|
||||
report_id, "generating", base_progress,
|
||||
f"正在生成章节: {section.title} ({section_num}/{total_sections})",
|
||||
t('progress.generatingSection', title=section.title, current=section_num, total=total_sections),
|
||||
current_section=section.title,
|
||||
completed_sections=completed_section_titles
|
||||
)
|
||||
|
||||
|
||||
if progress_callback:
|
||||
progress_callback(
|
||||
"generating",
|
||||
base_progress,
|
||||
f"正在生成章节: {section.title} ({section_num}/{total_sections})"
|
||||
"generating",
|
||||
base_progress,
|
||||
t('progress.generatingSection', title=section.title, current=section_num, total=total_sections)
|
||||
)
|
||||
|
||||
# 生成主章节内容
|
||||
@@ -1691,17 +1691,17 @@ class ReportAgent:
|
||||
ReportManager.update_progress(
|
||||
report_id, "generating",
|
||||
base_progress + int(70 / total_sections),
|
||||
f"章节 {section.title} 已完成",
|
||||
t('progress.sectionDone', title=section.title),
|
||||
current_section=None,
|
||||
completed_sections=completed_section_titles
|
||||
)
|
||||
|
||||
# 阶段3: 组装完整报告
|
||||
if progress_callback:
|
||||
progress_callback("generating", 95, "正在组装完整报告...")
|
||||
progress_callback("generating", 95, t('progress.assemblingReport'))
|
||||
|
||||
ReportManager.update_progress(
|
||||
report_id, "generating", 95, "正在组装完整报告...",
|
||||
report_id, "generating", 95, t('progress.assemblingReport'),
|
||||
completed_sections=completed_section_titles
|
||||
)
|
||||
|
||||
@@ -1723,12 +1723,12 @@ class ReportAgent:
|
||||
# 保存最终报告
|
||||
ReportManager.save_report(report)
|
||||
ReportManager.update_progress(
|
||||
report_id, "completed", 100, "报告生成完成",
|
||||
report_id, "completed", 100, t('progress.reportComplete'),
|
||||
completed_sections=completed_section_titles
|
||||
)
|
||||
|
||||
if progress_callback:
|
||||
progress_callback("completed", 100, "报告生成完成")
|
||||
progress_callback("completed", 100, t('progress.reportComplete'))
|
||||
|
||||
logger.info(f"报告生成完成: {report_id}")
|
||||
|
||||
@@ -1752,7 +1752,7 @@ class ReportAgent:
|
||||
try:
|
||||
ReportManager.save_report(report)
|
||||
ReportManager.update_progress(
|
||||
report_id, "failed", -1, f"报告生成失败: {str(e)}",
|
||||
report_id, "failed", -1, t('progress.reportFailed', error=str(e)),
|
||||
completed_sections=completed_section_titles
|
||||
)
|
||||
except Exception:
|
||||
|
||||
@@ -17,6 +17,7 @@ from ..utils.logger import get_logger
|
||||
from .zep_entity_reader import ZepEntityReader, FilteredEntities
|
||||
from .oasis_profile_generator import OasisProfileGenerator, OasisAgentProfile
|
||||
from .simulation_config_generator import SimulationConfigGenerator, SimulationParameters
|
||||
from ..utils.locale import t
|
||||
|
||||
logger = get_logger('mirofish.simulation')
|
||||
|
||||
@@ -270,12 +271,12 @@ class SimulationManager:
|
||||
|
||||
# ========== 阶段1: 读取并过滤实体 ==========
|
||||
if progress_callback:
|
||||
progress_callback("reading", 0, "正在连接Zep图谱...")
|
||||
progress_callback("reading", 0, t('progress.connectingZepGraph'))
|
||||
|
||||
reader = ZepEntityReader()
|
||||
|
||||
if progress_callback:
|
||||
progress_callback("reading", 30, "正在读取节点数据...")
|
||||
progress_callback("reading", 30, t('progress.readingNodeData'))
|
||||
|
||||
filtered = reader.filter_defined_entities(
|
||||
graph_id=state.graph_id,
|
||||
@@ -288,8 +289,8 @@ class SimulationManager:
|
||||
|
||||
if progress_callback:
|
||||
progress_callback(
|
||||
"reading", 100,
|
||||
f"完成,共 {filtered.filtered_count} 个实体",
|
||||
"reading", 100,
|
||||
t('progress.readingComplete', count=filtered.filtered_count),
|
||||
current=filtered.filtered_count,
|
||||
total=filtered.filtered_count
|
||||
)
|
||||
@@ -305,8 +306,8 @@ class SimulationManager:
|
||||
|
||||
if progress_callback:
|
||||
progress_callback(
|
||||
"generating_profiles", 0,
|
||||
"开始生成...",
|
||||
"generating_profiles", 0,
|
||||
t('progress.startGenerating'),
|
||||
current=0,
|
||||
total=total_entities
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user