Skip to content

A Simple and Universal Swarm Intelligence Engine, Predicting Anything. 简洁通用的群体智能引擎,预测万物

fix(i18n): replace remaining hardcoded language directives in LLM prompts

ghostubbornf75c6487b30c
diff --git a/backend/app/services/oasis_profile_generator.py b/backend/app/services/oasis_profile_generator.py
index 57836c53..0e473668 100644
--- a/backend/app/services/oasis_profile_generator.py
+++ b/backend/app/services/oasis_profile_generator.py
@@ -20,6 +20,7 @@ from zep_cloud.client import Zep
from ..config import Config
from ..utils.logger import get_logger
+from ..utils.locale import get_language_instruction
from .zep_entity_reader import EntityNode, ZepEntityReader
logger = get_logger('mirofish.oasis_profile')
@@ -670,8 +671,8 @@ class OasisProfileGenerator:
def _get_system_prompt(self, is_individual: bool) -> str:
"""获取系统提示词"""
- base_prompt = "你是社交媒体用户画像生成专家。生成详细、真实的人设用于舆论模拟,最大程度还原已有现实情况。必须返回有效的JSON格式,所有字符串值不能包含未转义的换行符。使用中文。"
- return base_prompt
+ base_prompt = "你是社交媒体用户画像生成专家。生成详细、真实的人设用于舆论模拟,最大程度还原已有现实情况。必须返回有效的JSON格式,所有字符串值不能包含未转义的换行符。"
+ return f"{base_prompt}\n\n{get_language_instruction()}"
def _build_individual_persona_prompt(
self,
@@ -717,7 +718,7 @@ class OasisProfileGenerator:
重要:
- 所有字段值必须是字符串或数字,不要使用换行符
- persona必须是一段连贯的文字描述
-- 使用中文(除了gender字段必须用英文male/female)
+- {get_language_instruction()} (gender字段必须用英文male/female)
- 内容要与实体信息保持一致
- age必须是有效的整数,gender必须是"male"或"female"
"""
@@ -766,7 +767,7 @@ class OasisProfileGenerator:
重要:
- 所有字段值必须是字符串或数字,不允许null值
- persona必须是一段连贯的文字描述,不要使用换行符
-- 使用中文(除了gender字段必须用英文"other")
+- {get_language_instruction()} (gender字段必须用英文"other")
- age必须是整数30,gender必须是字符串"other"
- 机构账号发言要符合其身份定位"""
diff --git a/backend/app/services/ontology_generator.py b/backend/app/services/ontology_generator.py
index 2d0b2304..316eb238 100644
--- a/backend/app/services/ontology_generator.py
+++ b/backend/app/services/ontology_generator.py
@@ -67,7 +67,7 @@ ONTOLOGY_SYSTEM_PROMPT = """你是一个专业的知识图谱本体设计专家
"attributes": []
}
],
- "analysis_summary": "对文本内容的简要分析说明(中文)"
+ "analysis_summary": "对文本内容的简要分析说明"
}
```
diff --git a/backend/app/services/report_agent.py b/backend/app/services/report_agent.py
index 7a4c8b34..a2b3a978 100644
--- a/backend/app/services/report_agent.py
+++ b/backend/app/services/report_agent.py
@@ -653,9 +653,9 @@ SECTION_SYSTEM_PROMPT_TEMPLATE = """\
- 这些引用是模拟预测的核心证据
3. 【语言一致性 - 引用内容必须翻译为报告语言】
- - 工具返回的内容可能包含英文或中英文混杂的表述
- - 如果模拟需求和材料原文是中文的,报告必须全部使用中文撰写
- - 当你引用工具返回的英文或中英混杂内容时,必须将其翻译为流畅的中文后再写入报告
+ - 工具返回的内容可能包含与报告语言不同的表述
+ - 报告必须全部使用与用户指定语言一致的语言撰写
+ - 当你引用工具返回的其他语言内容时,必须将其翻译为报告语言后再写入
- 翻译时保持原意不变,确保表述自然通顺
- 这一规则同时适用于正文和引用块(> 格式)中的内容
diff --git a/backend/app/services/zep_tools.py b/backend/app/services/zep_tools.py
index 384cf540..832ce468 100644
--- a/backend/app/services/zep_tools.py
+++ b/backend/app/services/zep_tools.py
@@ -18,6 +18,7 @@ from zep_cloud.client import Zep
from ..config import Config
from ..utils.logger import get_logger
from ..utils.llm_client import LLMClient
+from ..utils.locale import get_locale
from ..utils.zep_paging import fetch_all_nodes, fetch_all_edges
logger = get_logger('mirofish.zep_tools')
@@ -1695,7 +1696,8 @@ class ZepToolsService:
for interview in interviews:
interview_texts.append(f"【{interview.agent_name}({interview.agent_role})】\n{interview.response[:500]}")
- system_prompt = """你是一个专业的新闻编辑。请根据多位受访者的回答,生成一份采访摘要。
+ quote_instruction = "引用受访者原话时使用中文引号「」" if get_locale() == 'zh' else 'Use quotation marks "" when quoting interviewees'
+ system_prompt = f"""你是一个专业的新闻编辑。请根据多位受访者的回答,生成一份采访摘要。
摘要要求:
1. 提炼各方主要观点
@@ -1708,7 +1710,7 @@ class ZepToolsService:
- 使用纯文本段落,用空行分隔不同部分
- 不要使用Markdown标题(如#、##、###)
- 不要使用分割线(如---、***)
-- 引用受访者原话时使用中文引号「」
+- {quote_instruction}
- 可以使用**加粗**标记关键词,但不要使用其他Markdown语法"""
user_prompt = f"""采访主题:{interview_requirement}