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 }}'