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
+7
View File
@@ -48,6 +48,13 @@ class HttpLLMClient:
self._retry_backoff = retry_backoff
self._client = httpx.Client(timeout=timeout_sec, transport=transport)
def __enter__(self) -> HttpLLMClient:
"""支持 with 块:退出时自动关闭底层连接。"""
return self
def __exit__(self, exc_type, exc_val, exc_tb) -> None:
self._client.close()
def chat(
self,
*,
+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 "")