test: 清理 backlog——chat_structured 超限检测 + client 上下文管理器

This commit is contained in:
lhl
2026-08-09 09:15:36 +08:00
parent a5eaec4de8
commit cb2deda08a
5 changed files with 56 additions and 5 deletions
+3
View File
@@ -133,6 +133,9 @@ class InferenceEngine:
retry_count: int = 2,
) -> StructuredResult:
rendered = self._render_prompt(prompt, variables)
if self._estimator(rendered) > self._max_context_tokens:
variables = self._apply_truncation(rendered, variables)
rendered = self._render_prompt(prompt, variables)
# 追加 schema 约束说明(不强制模板支持)
schema_hint = json.dumps(schema, ensure_ascii=False) if schema else ""
base_rendered = rendered + (f'\n\n请输出符合以下 JSON Schema 的 JSON{schema_hint}' if schema_hint else "")