From f9b5b60c68e8ea47727875cee9890addf46ccd1a Mon Sep 17 00:00:00 2001 From: yumoqing Date: Sat, 5 Sep 2026 10:24:44 +0800 Subject: [PATCH] =?UTF-8?q?fix(inference):=20=E8=B6=85=E6=97=B6=E6=A0=B9?= =?UTF-8?q?=E5=9B=A0=E5=8F=8C=E4=BF=AE=E2=80=94=E2=80=94=E6=8A=A5=E9=94=99?= =?UTF-8?q?=E7=94=A8repr(TimeoutError=E7=A9=BAstr)+=E9=87=8D=E8=AF=95print?= =?UTF-8?q?=E8=BF=9B=E5=BA=94=E7=94=A8=E6=97=A5=E5=BF=97;chat=5Finference?= =?UTF-8?q?=E6=94=AF=E6=8C=81=5Ftimeout=E5=8D=95=E6=AC=A1=E8=B6=85?= =?UTF-8?q?=E6=97=B6=E8=A6=86=E7=9B=96(=E4=B8=8A=E9=99=90900=E7=A7=92,?= =?UTF-8?q?=E9=95=BF=E6=96=87=E6=A1=A3=E6=8F=90=E5=8F=96=E7=94=A8)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pipeline_llm/inference.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/pipeline_llm/inference.py b/pipeline_llm/inference.py index 2c2fcab..b287139 100644 --- a/pipeline_llm/inference.py +++ b/pipeline_llm/inference.py @@ -318,12 +318,16 @@ async def _call_upstream_chat(ctx, payload): return data except (asyncio.TimeoutError, aiohttp.ClientError) as e: last = e + # TimeoutError 的 str() 是空串,用 repr 保证消息真实可行动 + detail = repr(e) or type(e).__name__ + # print 确保进应用日志(模块 logger 未接应用日志管道,2026-09-04 实测) + print("[inference] 上游瞬时错误重试 %d/%d: %s (url=%s)" % ( + attempt + 1, _MAX_ATTEMPTS, detail, url.split('?')[0])) if attempt < _MAX_ATTEMPTS - 1: - logger.warning("inference: 瞬时错误重试 %d/%d: %s", - attempt + 1, _MAX_ATTEMPTS, e) await asyncio.sleep(2 * (attempt + 1)) continue - raise ValueError('上游调用失败(重试 %d 次仍失败): %s' % (_MAX_ATTEMPTS, e)) + raise ValueError('上游调用失败(重试 %d 次仍失败,%s): %s' % ( + _MAX_ATTEMPTS, type(e).__name__, detail)) raise last if last else ValueError('上游调用失败') @@ -346,12 +350,16 @@ async def chat_inference(org_id, user_id, payload, model_name='', task_ref=''): # 用途标记(辅助任务走辅助模型链):取出后从 payload 剥离,不透传给上游 purpose = (payload.pop('_purpose', '') or '') + # 单次调用超时覆盖(长文本提取等慢任务):剥离不透传,上限 900 秒 + req_timeout = int(_fnum(payload.pop('_timeout', 0)) or 0) est = max(_texts_len(payload.get('messages')) // EST_TOKENS_PER_CHAR, 200) db, dbname = _get_db() async with db.sqlorContext(dbname) as sor: ctx = await _resolve_call( sor, org_id, user_id or '', model_name, 't2t', est, task_ref, purpose) + if req_timeout > 0: + ctx['timeout'] = min(req_timeout, 900) try: data = await _call_upstream_chat(ctx, payload) except Exception as e: