feat: 贯通 context_window 配置并按 token 预算裁剪对话历史

This commit is contained in:
2026-09-20 14:22:53 +08:00
parent 8251a57010
commit 4114b0b4fb
21 changed files with 307 additions and 42 deletions
+11
View File
@@ -43,7 +43,18 @@ class ServerLlmRuntimeGateway(LlmRuntimeGateway):
str(k): str(v)
for k, v in (data.get("extraHeaders") or {}).items()
},
context_window=_optional_positive_int(data.get("contextWindow")),
)
except Exception:
logger.exception("拉取 Server LLM runtime 失败 company_id=%s", company_id)
return None
def _optional_positive_int(v) -> int | None:
if v is None:
return None
try:
n = int(v)
except (TypeError, ValueError):
return None
return n if n > 0 else None