refactor: streamline frontend language and shared UI utilities

This commit is contained in:
leefer
2026-07-22 23:45:57 +08:00
parent 18aed6a80f
commit 50dbb8a3ff
6 changed files with 155 additions and 118 deletions
+14 -24
View File
@@ -459,7 +459,7 @@ class DashboardService:
profile = self._resolved_llm_profile()
source = str(profile.get("source") or "none")
if source == "none" or not self._profile_configured(profile.get("primary") or {}):
raise ValueError("请配置个人 LLM,或使用已开通会员的平台模型")
raise ValueError("智能功能尚未配置,请联系管理员")
if source == "platform":
limit = max(1, int(self._system_credentials.get("member_daily_limit") or 50))
if self._platform_usage_today() >= limit:
@@ -1126,18 +1126,14 @@ class DashboardService:
self.llm_fallback_model,
)
compiled["compiler"] = "llm_fallback"
notice = f"主模型调用失败,已自动切换辅助模型。{primary_error}" if primary_error else "已使用辅助模型编译"
notice = "智能策略生成服务已自动切换"
except LLMCompilerError as exc:
fallback_error = str(exc)
compiled = compile_local_strategy(prompt, regime)
notice = f"主模型和辅助模型均不可用,已使用本地模板。主模型:{primary_error or '未配置'};辅助模型:{fallback_error}"
notice = "智能策略生成暂不可用,已使用本地模板。"
if compiled is None:
compiled = compile_local_strategy(prompt, regime)
notice = (
f"主模型调用失败且未配置辅助模型,已使用本地模板:{primary_error}"
if primary_error
else "尚未配置 LLM,当前使用本地受控模板编译。"
)
notice = "智能策略生成暂不可用,已使用本地模板。"
compiled["formula"] = self.screener.validate_formula(compiled["formula"])
compiled["notice"] = notice
if source in {"personal", "platform"}:
@@ -1234,13 +1230,10 @@ class DashboardService:
self.record_llm_usage(
"mentor", source, self.llm_fallback_model, "failed"
)
raise ValueError(
f"主模型和辅助模型均不可用。主模型:{primary_error or '未配置'}"
f"辅助模型:{fallback_error}"
) from exc
raise ValueError("智能解读服务暂不可用,请稍后重试。") from exc
if result is None:
self.record_llm_usage("mentor", source, self.llm_primary_model, "failed")
raise ValueError(f"主模型不可用且未配置辅助模型:{primary_error}")
raise ValueError("智能解读服务暂不可用,请稍后重试。")
self.record_llm_usage(
"mentor",
source,
@@ -1262,7 +1255,7 @@ class DashboardService:
"compiler": compiler,
"requested_trade_date": trade_date,
"data_trade_date": context["data_trade_date"],
"notice": "主模型调用失败,已自动切换辅助模型" if compiler == "fallback" else "",
"notice": "智能解读已自动切换可用服务" if compiler == "fallback" else "",
}
def mentor_messages(self, mentor_id: str, trade_date: str) -> list[dict[str, Any]]:
@@ -2196,7 +2189,7 @@ class DashboardService:
**result,
"mode": mode,
"compiler": compiler,
"notice": "主模型调用失败,已自动切换辅助模型" if compiler == "fallback" else "",
"notice": "智能解读已自动切换可用服务" if compiler == "fallback" else "",
}
def _call_heaven_agent(self, mode: str, context: dict[str, Any]) -> tuple[dict[str, Any], str]:
@@ -2236,12 +2229,9 @@ class DashboardService:
self.record_llm_usage(
f"heaven_{mode}", source, self.llm_fallback_model, "failed"
)
raise ValueError(
f"主模型和辅助模型均不可用。主模型:{primary_error or '未配置'}"
f"辅助模型:{exc}"
) from exc
raise ValueError("智能解读服务暂不可用,请稍后重试。") from exc
self.record_llm_usage(f"heaven_{mode}", source, self.llm_primary_model, "failed")
raise ValueError(f"主模型不可用且未配置辅助模型:{primary_error}")
raise ValueError("智能解读服务暂不可用,请稍后重试。")
def _heaven_index_context(
self,
@@ -2612,7 +2602,7 @@ class DashboardService:
"schema_version": 3,
"cached": False,
"updated_at": datetime.now().astimezone().isoformat(timespec="seconds"),
"notice": f"游资接口不可用:{exc}",
"notice": "龙虎榜数据暂不可用,请稍后重试。",
},
"summary": {
"trader_count": 0,
@@ -2640,7 +2630,7 @@ class DashboardService:
"status": "unavailable",
"schema_version": 3,
"cached": False,
"notice": "公共行情尚未配置,暂无龙虎榜数据。",
"notice": "龙虎榜数据暂不可用,请联系管理员检查行情配置",
},
"summary": {
"trader_count": 0,
@@ -2997,7 +2987,7 @@ class DashboardService:
compact_date = normalize_date(resolved_date)
intraday_points: list[dict[str, Any]] = []
intraday_status = "unavailable"
intraday_notice = "未配置 Tushare Token,分时数据不可用。"
intraday_notice = "分时行情暂不可用。"
if self.configured:
cache_key = f"{code}:{compact_date}"
@@ -3023,7 +3013,7 @@ class DashboardService:
intraday_notice = "该交易日暂无分时数据。"
except TushareError as exc:
intraday_status = "unavailable"
intraday_notice = f"Tushare 分时接口不可用:{exc}"
intraday_notice = "分时行情暂不可用,请稍后重试。"
prices = list(detail.get("prices") or [])[-60:]
stock = dict(detail.get("stock") or {"code": code})