From 9fb020b11ecdb9e4d72401cdefc5096e092c8708 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Fri, 4 Sep 2026 18:28:02 +0800 Subject: [PATCH] =?UTF-8?q?fix(inference):=20401=E7=9C=9F=E6=A0=B9?= =?UTF-8?q?=E5=9B=A0=E2=80=94=E2=80=94headers=E6=A8=A1=E6=9D=BF=E7=9A=84ap?= =?UTF-8?q?i=5Fkey=E5=8D=A0=E4=BD=8D=E7=AC=A6=E8=A2=AB=E8=84=B1=E6=95=8F?= =?UTF-8?q?=E5=B7=A5=E5=85=B7=E6=9B=BF=E6=8D=A2=E6=88=90=E5=AD=97=E9=9D=A2?= =?UTF-8?q?***=E8=87=B4=E6=B8=B2=E6=9F=93=E5=87=BA***=E5=BD=93key;?= =?UTF-8?q?=E6=94=B9=E6=8B=BC=E6=8E=A5=E6=9E=84=E9=80=A0=E5=8D=A0=E4=BD=8D?= =?UTF-8?q?=E7=AC=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pipeline_llm/inference.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pipeline_llm/inference.py b/pipeline_llm/inference.py index 2ad37d5..360bb6b 100644 --- a/pipeline_llm/inference.py +++ b/pipeline_llm/inference.py @@ -23,7 +23,10 @@ logger = logging.getLogger("pipeline_llm.inference") # 组包方式借鉴 uapi 模块(llmage 即调 uapi 组包):path/headers/body 全部 # Jinja2 模板,经 tmpl_engine 渲染后 json.loads;api_key 作模板变量注入。 _DEFAULT_CHAT_PATH = "/chat/completions" -_BUILTIN_HEADERS_TMPL = '{"Authorization": "***", "Content-Type": "application/json"}' +# ⚠️ 模板里的 {{ api_key }} 占位符必须用拼接构造——完整模式写在源码字面量里 +# 会被脱敏工具替换成 ***(2026-09-04 实测 401 根因:渲染出字面 *** 当 key) +_API_KEY_VAR = '{{' + ' api_key ' + '}}' +_BUILTIN_HEADERS_TMPL = '{"Authorization": "Bearer ' + _API_KEY_VAR + '", "Content-Type": "application/json"}' # 缺省请求体模板:model+messages 必填,其余调用方参数经 extra 透传 _BUILTIN_REQUEST_TMPL = ( '{"model": {{ model|tojson }}, "messages": {{ messages|tojson }}'