feat(i18n): inject language instruction into LLM system prompts
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
import json
|
||||
from typing import Dict, Any, List, Optional
|
||||
from ..utils.llm_client import LLMClient
|
||||
from ..utils.locale import get_language_instruction
|
||||
|
||||
|
||||
# 本体生成的系统提示词
|
||||
@@ -188,8 +189,9 @@ class OntologyGenerator:
|
||||
additional_context
|
||||
)
|
||||
|
||||
system_prompt = f"{ONTOLOGY_SYSTEM_PROMPT}\n\n{get_language_instruction()}"
|
||||
messages = [
|
||||
{"role": "system", "content": ONTOLOGY_SYSTEM_PROMPT},
|
||||
{"role": "system", "content": system_prompt},
|
||||
{"role": "user", "content": user_message}
|
||||
]
|
||||
|
||||
|
||||
@@ -21,6 +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 .zep_tools import (
|
||||
ZepToolsService,
|
||||
SearchResult,
|
||||
@@ -1162,7 +1163,7 @@ class ReportAgent:
|
||||
if progress_callback:
|
||||
progress_callback("planning", 30, "正在生成报告大纲...")
|
||||
|
||||
system_prompt = PLAN_SYSTEM_PROMPT
|
||||
system_prompt = f"{PLAN_SYSTEM_PROMPT}\n\n{get_language_instruction()}"
|
||||
user_prompt = PLAN_USER_PROMPT_TEMPLATE.format(
|
||||
simulation_requirement=self.simulation_requirement,
|
||||
total_nodes=context.get('graph_statistics', {}).get('total_nodes', 0),
|
||||
@@ -1258,6 +1259,7 @@ class ReportAgent:
|
||||
section_title=section.title,
|
||||
tools_description=self._get_tools_description(),
|
||||
)
|
||||
system_prompt = f"{system_prompt}\n\n{get_language_instruction()}"
|
||||
|
||||
# 构建用户prompt - 每个已完成章节各传入最大4000字
|
||||
if previous_sections:
|
||||
@@ -1805,6 +1807,7 @@ class ReportAgent:
|
||||
report_content=report_content if report_content else "(暂无报告)",
|
||||
tools_description=self._get_tools_description(),
|
||||
)
|
||||
system_prompt = f"{system_prompt}\n\n{get_language_instruction()}"
|
||||
|
||||
# 构建消息
|
||||
messages = [{"role": "system", "content": system_prompt}]
|
||||
|
||||
@@ -20,6 +20,7 @@ from openai import OpenAI
|
||||
|
||||
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.simulation_config')
|
||||
@@ -585,7 +586,8 @@ class SimulationConfigGenerator:
|
||||
- reasoning (string): 简要说明为什么这样配置"""
|
||||
|
||||
system_prompt = "你是社交媒体模拟专家。返回纯JSON格式,时间配置需符合中国人作息习惯。"
|
||||
|
||||
system_prompt = f"{system_prompt}\n\n{get_language_instruction()}"
|
||||
|
||||
try:
|
||||
return self._call_llm_with_retry(prompt, system_prompt)
|
||||
except Exception as e:
|
||||
@@ -701,7 +703,8 @@ class SimulationConfigGenerator:
|
||||
}}"""
|
||||
|
||||
system_prompt = "你是舆论分析专家。返回纯JSON格式。注意 poster_type 必须精确匹配可用实体类型。"
|
||||
|
||||
system_prompt = f"{system_prompt}\n\n{get_language_instruction()}"
|
||||
|
||||
try:
|
||||
return self._call_llm_with_retry(prompt, system_prompt)
|
||||
except Exception as e:
|
||||
@@ -864,7 +867,8 @@ class SimulationConfigGenerator:
|
||||
}}"""
|
||||
|
||||
system_prompt = "你是社交媒体行为分析专家。返回纯JSON,配置需符合中国人作息习惯。"
|
||||
|
||||
system_prompt = f"{system_prompt}\n\n{get_language_instruction()}"
|
||||
|
||||
try:
|
||||
result = self._call_llm_with_retry(prompt, system_prompt)
|
||||
llm_configs = {cfg["agent_id"]: cfg for cfg in result.get("agent_configs", [])}
|
||||
|
||||
Reference in New Issue
Block a user