sycommon-python-lib 0.2.7a10__py3-none-any.whl → 0.2.7a11__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
sycommon/llm/get_llm.py CHANGED
@@ -10,7 +10,17 @@ from sycommon.middleware.context import current_llm_api_key
10
10
 
11
11
 
12
12
  def resolve_api_key(config_apikey: Optional[str]) -> str:
13
- """LLM 网关 apiKey 取值:per-user ContextVar → 配置全局 key → "-" 兜底。"""
13
+ """LLM 网关 apiKey 取值:override → per-user 派生 key → 配置全局 key → "-" 兜底。
14
+
15
+ llm_key_override 优先级最高:stream_chat 在 LLM 报错降级时 set="global" 强制
16
+ 走 nacos 全局 apiKey,或 set 成显式 key。默认 None 时走 per-user 派生 key。
17
+ """
18
+ from sycommon.middleware.context import llm_key_override
19
+ ov = llm_key_override.get()
20
+ if ov == "global":
21
+ return config_apikey or "-"
22
+ if ov: # 显式指定 key
23
+ return ov
14
24
  return current_llm_api_key.get() or config_apikey or "-"
15
25
 
16
26
 
@@ -7,3 +7,10 @@ current_headers = contextvars.ContextVar("headers", default=None)
7
7
  # per-user LLM 网关 apiKey:agent 创建入口 set,get_llm 读取,沿 task 树传播。
8
8
  # 为 None 时 get_llm 回退到 LLMConfig.apiKey 全局 key。
9
9
  current_llm_api_key = contextvars.ContextVar("llm_api_key", default=None)
10
+
11
+ # LLM 网关 apiKey 降级开关(resolve_api_key 最先检查,优先级高于派生 key):
12
+ # "global" = 强制用 nacos 全局 LLMConfig.apiKey(派生 key 失败时兜底)
13
+ # 其它非空字符串 = 直接用该 key
14
+ # None = 走 per-user 派生 key(默认,正常路径)
15
+ # 沿 asyncio task 树传播,请求结束自动重置 → 每次新请求仍优先派生 key。
16
+ llm_key_override = contextvars.ContextVar("llm_key_override", default=None)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sycommon-python-lib
3
- Version: 0.2.7a10
3
+ Version: 0.2.7a11
4
4
  Summary: Add your description here
5
5
  Requires-Python: >=3.11
6
6
  Description-Content-Type: text/markdown
@@ -200,7 +200,7 @@ sycommon/heartbeat_process/heartbeat_process_manager.py,sha256=24qUKs8qegdWHqcox
200
200
  sycommon/heartbeat_process/heartbeat_process_worker.py,sha256=duuAEFwda43Y6pZE8tOOspitlyxecaFsg1n1iH9jQDQ,16863
201
201
  sycommon/llm/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
202
202
  sycommon/llm/embedding.py,sha256=n2PtKlfJ4E1-V8DIHTilR-y9y1TYB5iaATlWOKjid28,19878
203
- sycommon/llm/get_llm.py,sha256=Pl5tdCNaNevLutU3PvzYQwPFeVkFlv-Pmsj4x9aRRoY,7973
203
+ sycommon/llm/get_llm.py,sha256=Mi4rWB07QQzv0NgAGOCXyB9Yd7jl_MbKd1J5Qml8BMk,8402
204
204
  sycommon/llm/llm_logger.py,sha256=zWK27OWNPs5aMOlqYXyrPK8IvtXmJLGi8HnTKPJ-1Uw,3846
205
205
  sycommon/llm/llm_tokens.py,sha256=yGEessxfk5wRMrPGyWHhiiIIQFDVT23FSaqnwqHGCoY,4712
206
206
  sycommon/llm/llm_with_token_tracking.py,sha256=VJYHQSSuqvAbJ7qFs7Zml_thFDZoqL2rXFj8Nrj6rNo,13834
@@ -225,7 +225,7 @@ sycommon/logging/sql_logger.py,sha256=Kx60dy7swbq3rcRRVV1fZtbvyo4yypGxduYlF0JHvr
225
225
  sycommon/mcp_server/__init__.py,sha256=iweQoesjnIl4I9LA98ZARc8p3AatxWcyLS4uYi_58sU,266
226
226
  sycommon/mcp_server/server.py,sha256=NjPtEN6_QsI-Cc2tuPAew_PorBEJ60Xuxjaox0Dku4E,6269
227
227
  sycommon/middleware/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
228
- sycommon/middleware/context.py,sha256=SwE6LvHkk8d3m2OcZfdfpr-vpeQMcjimo6IMWzgyb4o,389
228
+ sycommon/middleware/context.py,sha256=hCBhz-5FQ19OI3YP_uPlccDdIdnuLKltPwF4LEfCl4s,856
229
229
  sycommon/middleware/cors.py,sha256=0B5d_ovD56wcH9TfktRs88Q09R9f8Xx5h5ALWYvE8Iw,600
230
230
  sycommon/middleware/docs.py,sha256=bVdDBIHXGVBv562MQLSroa1DgHoObxR9gFzv71PIejg,1187
231
231
  sycommon/middleware/exception.py,sha256=UAy0tKijI_2JoKjwT3h62aL-tybftP3IETvcr26NOao,2883
@@ -306,8 +306,8 @@ sycommon/tools/syemail.py,sha256=BDFhgf7WDOQeTcjxJEQdu0dQhnHFPO_p3eI0-Ni3LhQ,561
306
306
  sycommon/tools/timing.py,sha256=OiiE7P07lRoMzX9kzb8sZU9cDb0zNnqIlY5pWqHcnkY,2064
307
307
  sycommon/xxljob/__init__.py,sha256=7eoBlQxv-B39IfRSCY2bkqdGYs1QRe1umAWd88VMEEM,86
308
308
  sycommon/xxljob/xxljob_service.py,sha256=1yifwIBNGsCIxLnQjHKiBlbsigc_zvPH-dMTZcNxe-Q,7649
309
- sycommon_python_lib-0.2.7a10.dist-info/METADATA,sha256=0BOZBp8TXGDqzBSqs9DqaYwJmoe6pmJ5MOfLIEKLxyY,7962
310
- sycommon_python_lib-0.2.7a10.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
311
- sycommon_python_lib-0.2.7a10.dist-info/entry_points.txt,sha256=gsR4SssKxDWjRU8ggidzNcdMXDPRSKRS7UaGyNP84Qg,92
312
- sycommon_python_lib-0.2.7a10.dist-info/top_level.txt,sha256=RgphKrg7nJyZ7irJqbxFr-5H2LUYTvI7ivoWZH2hcD0,29
313
- sycommon_python_lib-0.2.7a10.dist-info/RECORD,,
309
+ sycommon_python_lib-0.2.7a11.dist-info/METADATA,sha256=uNouGqbjoHhu62nFa67_11WrNGxBCdNgppLjQduJA1s,7962
310
+ sycommon_python_lib-0.2.7a11.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
311
+ sycommon_python_lib-0.2.7a11.dist-info/entry_points.txt,sha256=gsR4SssKxDWjRU8ggidzNcdMXDPRSKRS7UaGyNP84Qg,92
312
+ sycommon_python_lib-0.2.7a11.dist-info/top_level.txt,sha256=RgphKrg7nJyZ7irJqbxFr-5H2LUYTvI7ivoWZH2hcD0,29
313
+ sycommon_python_lib-0.2.7a11.dist-info/RECORD,,