refactor(settings): 统一语言设置,合并 interface_language 和 ai_language
- 后端 Schema 将 interface_language 和 ai_language 合并为 language - 前端设置界面只保留一个语言选项 - AI 回复语言统一使用 language 设置 - 更新协议文档 - 新增数据库迁移脚本
This commit is contained in:
@@ -12,10 +12,10 @@ def build_agent_prompt(
|
||||
*,
|
||||
agent_type: AgentType,
|
||||
llm_config: SystemAgentLLMConfig | None = None,
|
||||
ai_language: str = "zh-CN",
|
||||
language: str = "zh-CN",
|
||||
) -> str:
|
||||
_ = agent_type, llm_config
|
||||
role_playing = get_worker_role_playing(ai_language)
|
||||
output_rules = get_worker_output_rules(ai_language)
|
||||
role_playing = get_worker_role_playing(language)
|
||||
output_rules = get_worker_output_rules(language)
|
||||
content = f"[role_playing]\n{role_playing}\n\n[output_json_rules]\n{output_rules}"
|
||||
return wrap_section("agent", content)
|
||||
|
||||
@@ -39,8 +39,8 @@ def _build_safety_section() -> str:
|
||||
)
|
||||
|
||||
|
||||
def _build_output_rules(*, ai_language: str) -> str:
|
||||
lang_label = _get_language_label(ai_language)
|
||||
def _build_output_rules(*, language: str) -> str:
|
||||
lang_label = _get_language_label(language)
|
||||
rules = [
|
||||
"[Language Requirement]",
|
||||
f"- You MUST respond in {lang_label}.",
|
||||
@@ -68,7 +68,7 @@ def _build_time_context(*, now_utc: datetime | None) -> str:
|
||||
def build_system_prompt(
|
||||
*,
|
||||
agent_type: AgentType,
|
||||
ai_language: str,
|
||||
language: str,
|
||||
llm_config: SystemAgentLLMConfig | None = None,
|
||||
tools: Sequence[Tool | dict[str, Any]] | None = None,
|
||||
now_utc: datetime | None = None,
|
||||
@@ -79,9 +79,9 @@ def build_system_prompt(
|
||||
build_agent_prompt(
|
||||
agent_type=agent_type,
|
||||
llm_config=llm_config,
|
||||
ai_language=ai_language,
|
||||
language=language,
|
||||
),
|
||||
build_tools_prompt(tools=tools) if tools else None,
|
||||
_build_output_rules(ai_language=ai_language),
|
||||
_build_output_rules(language=language),
|
||||
]
|
||||
return "\n\n".join(item for item in sections if item).strip()
|
||||
|
||||
@@ -101,14 +101,14 @@ answer: A complete reading covering overall judgment, current situation, final t
|
||||
sign_level: Must be exactly one of: 上上签 / 中上签 / 中下签 / 下下签. Always use the Chinese enum value regardless of language."""
|
||||
|
||||
|
||||
def get_worker_role_playing(ai_language: str) -> str:
|
||||
_ = ai_language
|
||||
def get_worker_role_playing(language: str) -> str:
|
||||
_ = language
|
||||
return _WORKER_ROLE_PLAYING
|
||||
|
||||
|
||||
def get_worker_output_rules(ai_language: str) -> str:
|
||||
if ai_language.startswith("en"):
|
||||
def get_worker_output_rules(language: str) -> str:
|
||||
if language.startswith("en"):
|
||||
return _WORKER_OUTPUT_RULES_EN
|
||||
if ai_language.startswith("zh-Hant") or ai_language.startswith("zh_Hant"):
|
||||
if language.startswith("zh-Hant") or language.startswith("zh_Hant"):
|
||||
return _WORKER_OUTPUT_RULES_ZH_HANT
|
||||
return _WORKER_OUTPUT_RULES_ZH_CN
|
||||
|
||||
@@ -265,15 +265,15 @@ class AgentScopeRunner:
|
||||
emit_text_events=True,
|
||||
emit_tool_events=False,
|
||||
)
|
||||
ai_language = "zh-CN"
|
||||
language = "zh-CN"
|
||||
if user_context.settings is not None:
|
||||
prefs = getattr(user_context.settings, "preferences", None)
|
||||
if prefs is not None:
|
||||
ai_language = getattr(prefs, "ai_language", "zh-CN") or "zh-CN"
|
||||
language = getattr(prefs, "language", "zh-CN") or "zh-CN"
|
||||
|
||||
system_prompt = build_system_prompt(
|
||||
agent_type=stage_config.agent_type,
|
||||
ai_language=ai_language,
|
||||
language=language,
|
||||
llm_config=stage_config.llm_config,
|
||||
tools=None,
|
||||
now_utc=datetime.now(timezone.utc),
|
||||
|
||||
@@ -11,12 +11,10 @@ _COUNTRY_PATTERN = re.compile(r"^[A-Z]{2}$")
|
||||
|
||||
|
||||
class PreferenceSettings(BaseModel):
|
||||
interface_language: str = "zh-CN"
|
||||
ai_language: str = "zh-CN"
|
||||
language: str = "zh-CN"
|
||||
timezone: str = "Asia/Shanghai"
|
||||
country: str = "US"
|
||||
|
||||
@field_validator("interface_language", "ai_language")
|
||||
@field_validator("language")
|
||||
@classmethod
|
||||
def validate_language(cls, value: str) -> str:
|
||||
if not _BCP47_PATTERN.fullmatch(value):
|
||||
@@ -32,14 +30,6 @@ class PreferenceSettings(BaseModel):
|
||||
raise ValueError("timezone must be a valid IANA timezone") from exc
|
||||
return value
|
||||
|
||||
@field_validator("country")
|
||||
@classmethod
|
||||
def validate_country(cls, value: str) -> str:
|
||||
normalized = value.upper()
|
||||
if not _COUNTRY_PATTERN.fullmatch(normalized):
|
||||
raise ValueError("country must be an ISO 3166-1 alpha-2 code")
|
||||
return normalized
|
||||
|
||||
|
||||
class NotificationSettings(BaseModel):
|
||||
allow_notifications: bool = True
|
||||
|
||||
Reference in New Issue
Block a user