同步已上线的智能分析执行协议、来源查询、图表报告与管理页面配套代码。 补齐数据库迁移、运行依赖和回归测试,保留原有指标计算口径。 统一午夜黑及其他主题的控件细节、中文和业务数字字体。 排除本地业务数据、凭据、预览、发布与验收产物。 验证:生产构建通过,320项前端回归通过;本轮仅同步Git,不再次部署。
52 lines
1.9 KiB
Python
52 lines
1.9 KiB
Python
"""Shared system limits, independent of model profiles and environment overrides."""
|
|
from contextlib import contextmanager
|
|
from contextvars import ContextVar
|
|
import json
|
|
from pathlib import Path
|
|
import time
|
|
|
|
_POLICY_PATH = Path(__file__).resolve().parents[1] / 'backend/src/main/resources/analysis-runtime-policy.json'
|
|
_policy = json.loads(_POLICY_PATH.read_text(encoding='utf-8'))
|
|
if (_policy.get('version') != 1 or
|
|
any(type(_policy.get(key)) is not int for key in (
|
|
'maxOutputTokens', 'turnTimeoutSeconds', 'requestTimeoutSeconds', 'finalizationReserveSeconds')) or
|
|
not 8192 <= _policy['maxOutputTokens'] <= 32768 or
|
|
not 60 <= _policy['finalizationReserveSeconds'] < _policy['requestTimeoutSeconds'] < _policy['turnTimeoutSeconds'] <= 3600):
|
|
raise ValueError('分析系统额度配置无效。')
|
|
|
|
MAX_OUTPUT_TOKENS = _policy['maxOutputTokens']
|
|
TURN_TIMEOUT_SECONDS = _policy['turnTimeoutSeconds']
|
|
REQUEST_TIMEOUT_SECONDS = _policy['requestTimeoutSeconds']
|
|
FINALIZATION_RESERVE_SECONDS = _policy['finalizationReserveSeconds']
|
|
_deadline = ContextVar('analysis_turn_deadline', default=None)
|
|
|
|
|
|
@contextmanager
|
|
def turn_scope():
|
|
token = _deadline.set(time.monotonic() + TURN_TIMEOUT_SECONDS)
|
|
try:
|
|
yield
|
|
finally:
|
|
_deadline.reset(token)
|
|
|
|
|
|
def turn_deadline():
|
|
return _deadline.get()
|
|
|
|
|
|
def remaining_seconds():
|
|
deadline = turn_deadline()
|
|
return max(0, deadline - time.monotonic()) if deadline is not None else TURN_TIMEOUT_SECONDS
|
|
|
|
|
|
def request_timeout(purpose='planning'):
|
|
reserve = 5 if purpose == 'final' else FINALIZATION_RESERVE_SECONDS + 60
|
|
available = remaining_seconds() - reserve
|
|
if available <= 0:
|
|
raise TimeoutError('本轮时间已保留用于整理已取得的证据。')
|
|
return min(REQUEST_TIMEOUT_SECONDS, available)
|
|
|
|
|
|
def native_timeout():
|
|
return max(0, remaining_seconds() - FINALIZATION_RESERVE_SECONDS)
|