sycommon-python-lib 0.2.7a8__py3-none-any.whl → 0.2.7a9__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 +8 -1
- sycommon/middleware/context.py +4 -0
- {sycommon_python_lib-0.2.7a8.dist-info → sycommon_python_lib-0.2.7a9.dist-info}/METADATA +1 -1
- {sycommon_python_lib-0.2.7a8.dist-info → sycommon_python_lib-0.2.7a9.dist-info}/RECORD +7 -7
- {sycommon_python_lib-0.2.7a8.dist-info → sycommon_python_lib-0.2.7a9.dist-info}/WHEEL +0 -0
- {sycommon_python_lib-0.2.7a8.dist-info → sycommon_python_lib-0.2.7a9.dist-info}/entry_points.txt +0 -0
- {sycommon_python_lib-0.2.7a8.dist-info → sycommon_python_lib-0.2.7a9.dist-info}/top_level.txt +0 -0
sycommon/llm/get_llm.py
CHANGED
|
@@ -6,6 +6,13 @@ from sycommon.llm.sy_langfuse import LangfuseInitializer
|
|
|
6
6
|
from sycommon.llm.usage_token import LLMWithAutoTokenUsage
|
|
7
7
|
from typing import Any, Optional, Union
|
|
8
8
|
from langchain_core.language_models import BaseChatModel
|
|
9
|
+
from sycommon.middleware.context import current_llm_api_key
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def resolve_api_key(config_apikey: Optional[str]) -> str:
|
|
13
|
+
"""LLM 网关 apiKey 取值:per-user ContextVar → 配置全局 key → "-" 兜底。"""
|
|
14
|
+
return current_llm_api_key.get() or config_apikey or "-"
|
|
15
|
+
|
|
9
16
|
|
|
10
17
|
_TIMEOUT_UNSET = object()
|
|
11
18
|
|
|
@@ -160,7 +167,7 @@ def get_llm(
|
|
|
160
167
|
"model_provider": llmConfig.provider,
|
|
161
168
|
"model": llmConfig.model,
|
|
162
169
|
"base_url": llmConfig.baseUrl,
|
|
163
|
-
"api_key": llmConfig.apiKey
|
|
170
|
+
"api_key": resolve_api_key(llmConfig.apiKey),
|
|
164
171
|
"callbacks": callbacks,
|
|
165
172
|
"temperature": temperature,
|
|
166
173
|
"streaming": streaming,
|
sycommon/middleware/context.py
CHANGED
|
@@ -3,3 +3,7 @@ import contextvars
|
|
|
3
3
|
current_trace_id = contextvars.ContextVar("trace_id", default=None)
|
|
4
4
|
|
|
5
5
|
current_headers = contextvars.ContextVar("headers", default=None)
|
|
6
|
+
|
|
7
|
+
# per-user LLM 网关 apiKey:agent 创建入口 set,get_llm 读取,沿 task 树传播。
|
|
8
|
+
# 为 None 时 get_llm 回退到 LLMConfig.apiKey 全局 key。
|
|
9
|
+
current_llm_api_key = contextvars.ContextVar("llm_api_key", default=None)
|
|
@@ -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=
|
|
203
|
+
sycommon/llm/get_llm.py,sha256=Pl5tdCNaNevLutU3PvzYQwPFeVkFlv-Pmsj4x9aRRoY,7973
|
|
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=
|
|
228
|
+
sycommon/middleware/context.py,sha256=SwE6LvHkk8d3m2OcZfdfpr-vpeQMcjimo6IMWzgyb4o,389
|
|
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.
|
|
310
|
-
sycommon_python_lib-0.2.
|
|
311
|
-
sycommon_python_lib-0.2.
|
|
312
|
-
sycommon_python_lib-0.2.
|
|
313
|
-
sycommon_python_lib-0.2.
|
|
309
|
+
sycommon_python_lib-0.2.7a9.dist-info/METADATA,sha256=de5Q1-h4FhDThktkPyzjht5hGhGN8L8ac1MJ-xMlRpg,7961
|
|
310
|
+
sycommon_python_lib-0.2.7a9.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
|
|
311
|
+
sycommon_python_lib-0.2.7a9.dist-info/entry_points.txt,sha256=gsR4SssKxDWjRU8ggidzNcdMXDPRSKRS7UaGyNP84Qg,92
|
|
312
|
+
sycommon_python_lib-0.2.7a9.dist-info/top_level.txt,sha256=RgphKrg7nJyZ7irJqbxFr-5H2LUYTvI7ivoWZH2hcD0,29
|
|
313
|
+
sycommon_python_lib-0.2.7a9.dist-info/RECORD,,
|
|
File without changes
|
{sycommon_python_lib-0.2.7a8.dist-info → sycommon_python_lib-0.2.7a9.dist-info}/entry_points.txt
RENAMED
|
File without changes
|
{sycommon_python_lib-0.2.7a8.dist-info → sycommon_python_lib-0.2.7a9.dist-info}/top_level.txt
RENAMED
|
File without changes
|