From e88e0bfc37f100062852cb774835d95c4c4f513c Mon Sep 17 00:00:00 2001 From: ymq Date: Sat, 5 Sep 2026 10:24:55 +0800 Subject: [PATCH] =?UTF-8?q?feat(llm=5Fbridge):=20llm=5Fcall/llm=5Fcall=5Fm?= =?UTF-8?q?sgs=E5=8A=A0timeout=E5=8F=82=E6=95=B0=E2=80=94=E2=80=94=5Ftimeo?= =?UTF-8?q?ut=E7=BB=8Fpayload=E9=80=8F=E4=BC=A0=E7=BB=9F=E4=B8=80=E6=8E=A8?= =?UTF-8?q?=E7=90=86=E7=AB=AF=E7=82=B9(=E6=8F=90=E5=8F=96=E7=AD=89?= =?UTF-8?q?=E9=95=BF=E4=BB=BB=E5=8A=A1=E8=B6=85=E7=AB=AF=E7=82=B9=E9=BB=98?= =?UTF-8?q?=E8=AE=A460=E7=A7=92)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pipeline_service/llm_bridge.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/pipeline_service/llm_bridge.py b/pipeline_service/llm_bridge.py index e7ee630..70b405e 100644 --- a/pipeline_service/llm_bridge.py +++ b/pipeline_service/llm_bridge.py @@ -105,7 +105,8 @@ def _no_llm_error(model_name=None, org_id=None) -> ValueError: async def llm_call(prompt: str, model: str = None, temperature: float = 0.7, - org_id: str = None, user_id: str = None, purpose: str = '') -> str: + org_id: str = None, user_id: str = None, purpose: str = '', + timeout: int = 0) -> str: """Call LLM and return text response. 统一走模型治理推理 API(门禁链 + 双维度记账)。 @@ -133,6 +134,8 @@ async def llm_call(prompt: str, model: str = None, temperature: float = 0.7, } if purpose: payload["_purpose"] = purpose + if timeout: + payload["_timeout"] = int(timeout) data = await _http_chat(payload, org_id or '0', user_id or '', model or '') try: return data["choices"][0]["message"]["content"] @@ -147,14 +150,18 @@ async def call_llm(tenant_id: str, prompt: str, model: str = None, temperature: async def llm_call_msgs(messages: list, model: str = None, temperature: float = 0.7, - org_id: str = None, user_id: str = None, purpose: str = '') -> str: + org_id: str = None, user_id: str = None, purpose: str = '', + timeout: int = 0) -> str: """Call LLM with full message array (system/user/assistant). purpose='utility':辅助任务(分类/选择/摘要),治理层按用途选模型链。 + timeout:单次上游调用超时秒数(0=用端点默认;上限 900,超长文本提取用)。 """ payload = {"model": model or '', "messages": messages, "temperature": temperature} if purpose: payload["_purpose"] = purpose + if timeout: + payload["_timeout"] = int(timeout) data = await _http_chat(payload, org_id or '0', user_id or '', model or '') try: return data["choices"][0]["message"]["content"]