sycommon-python-lib 0.1.56b13__py3-none-any.whl → 0.1.56b14__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/config/Config.py +7 -0
- sycommon/config/LangfuseConfig.py +15 -0
- sycommon/llm/get_llm.py +19 -1
- {sycommon_python_lib-0.1.56b13.dist-info → sycommon_python_lib-0.1.56b14.dist-info}/METADATA +2 -1
- {sycommon_python_lib-0.1.56b13.dist-info → sycommon_python_lib-0.1.56b14.dist-info}/RECORD +8 -7
- {sycommon_python_lib-0.1.56b13.dist-info → sycommon_python_lib-0.1.56b14.dist-info}/WHEEL +0 -0
- {sycommon_python_lib-0.1.56b13.dist-info → sycommon_python_lib-0.1.56b14.dist-info}/entry_points.txt +0 -0
- {sycommon_python_lib-0.1.56b13.dist-info → sycommon_python_lib-0.1.56b14.dist-info}/top_level.txt +0 -0
sycommon/config/Config.py
CHANGED
|
@@ -21,6 +21,7 @@ class Config(metaclass=SingletonMeta):
|
|
|
21
21
|
self.embedding_configs = []
|
|
22
22
|
self.reranker_configs = []
|
|
23
23
|
self.sentry_configs = []
|
|
24
|
+
self.langfuse_configs = []
|
|
24
25
|
self._process_config()
|
|
25
26
|
|
|
26
27
|
def get_llm_config(self, model_name):
|
|
@@ -47,6 +48,12 @@ class Config(metaclass=SingletonMeta):
|
|
|
47
48
|
return sentry
|
|
48
49
|
raise ValueError(f"No configuration found for server: {name}")
|
|
49
50
|
|
|
51
|
+
def get_langfuse_config(self, name):
|
|
52
|
+
for langfuse in self.langfuse_configs:
|
|
53
|
+
if langfuse.get('name') == name:
|
|
54
|
+
return langfuse
|
|
55
|
+
raise ValueError(f"No configuration found for server: {name}")
|
|
56
|
+
|
|
50
57
|
def _process_config(self):
|
|
51
58
|
llm_config_list = self.config.get('LLMConfig', [])
|
|
52
59
|
for llm_config in llm_config_list:
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
from pydantic import BaseModel
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class LangfuseConfig(BaseModel):
|
|
5
|
+
name: str
|
|
6
|
+
secretKey: str
|
|
7
|
+
publicKey: str
|
|
8
|
+
baseUrl: str
|
|
9
|
+
enable: bool
|
|
10
|
+
|
|
11
|
+
@classmethod
|
|
12
|
+
def from_config(cls, server_name: str):
|
|
13
|
+
from sycommon.config.Config import Config
|
|
14
|
+
langfuse_config = Config().get_langfuse_config(server_name)
|
|
15
|
+
return cls(**langfuse_config)
|
sycommon/llm/get_llm.py
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import os
|
|
1
2
|
from typing import Dict, Type, List, Optional, Callable, Any
|
|
3
|
+
from sycommon.config.Config import Config
|
|
2
4
|
from sycommon.llm.llm_logger import LLMLogger
|
|
3
5
|
from langchain_core.language_models import BaseChatModel
|
|
4
6
|
from langchain_core.runnables import Runnable, RunnableLambda, RunnableConfig
|
|
@@ -10,6 +12,7 @@ from pydantic import BaseModel, ValidationError, Field
|
|
|
10
12
|
from sycommon.config.LLMConfig import LLMConfig
|
|
11
13
|
from sycommon.llm.llm_tokens import TokensCallbackHandler
|
|
12
14
|
from sycommon.logging.kafka_log import SYLogger
|
|
15
|
+
from langfuse.langchain import CallbackHandler
|
|
13
16
|
|
|
14
17
|
|
|
15
18
|
class StructuredRunnableWithToken(Runnable):
|
|
@@ -230,6 +233,21 @@ def get_llm(
|
|
|
230
233
|
if not llmConfig:
|
|
231
234
|
raise Exception(f"无效的模型配置:{model}")
|
|
232
235
|
|
|
236
|
+
callbacks = [LLMLogger()]
|
|
237
|
+
|
|
238
|
+
config = Config().config
|
|
239
|
+
server_name = config.get('Name', '')
|
|
240
|
+
langfuse_configs = config.get('LangfuseConfig', [])
|
|
241
|
+
target_config = next(
|
|
242
|
+
(item for item in langfuse_configs if item.get('name') == server_name), None)
|
|
243
|
+
if target_config and target_config.get('enable', False):
|
|
244
|
+
os.environ["LANGFUSE_SECRET_KEY"] = target_config.get('secretKey', '')
|
|
245
|
+
os.environ["LANGFUSE_PUBLIC_KEY"] = target_config.get('publicKey', '')
|
|
246
|
+
os.environ["LANGFUSE_BASE_URL"] = target_config.get('baseUrl', '')
|
|
247
|
+
|
|
248
|
+
langfuse_handler = CallbackHandler()
|
|
249
|
+
callbacks += [langfuse_handler]
|
|
250
|
+
|
|
233
251
|
llm = init_chat_model(
|
|
234
252
|
model_provider=llmConfig.provider,
|
|
235
253
|
model=llmConfig.model,
|
|
@@ -237,7 +255,7 @@ def get_llm(
|
|
|
237
255
|
api_key="-",
|
|
238
256
|
temperature=0.1,
|
|
239
257
|
streaming=streaming,
|
|
240
|
-
callbacks=
|
|
258
|
+
callbacks=callbacks
|
|
241
259
|
)
|
|
242
260
|
|
|
243
261
|
if llm is None:
|
{sycommon_python_lib-0.1.56b13.dist-info → sycommon_python_lib-0.1.56b14.dist-info}/METADATA
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: sycommon-python-lib
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.56b14
|
|
4
4
|
Summary: Add your description here
|
|
5
5
|
Requires-Python: >=3.11
|
|
6
6
|
Description-Content-Type: text/markdown
|
|
@@ -13,6 +13,7 @@ Requires-Dist: kafka-python>=2.3.0
|
|
|
13
13
|
Requires-Dist: langchain>=1.2.0
|
|
14
14
|
Requires-Dist: langchain-core>=1.2.6
|
|
15
15
|
Requires-Dist: langchain-openai>=1.1.6
|
|
16
|
+
Requires-Dist: langfuse>=3.11.2
|
|
16
17
|
Requires-Dist: langgraph>=1.0.5
|
|
17
18
|
Requires-Dist: loguru>=0.7.3
|
|
18
19
|
Requires-Dist: mysql-connector-python>=9.5.0
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
command/cli.py,sha256=bP2LCLkRvfETIwWkVD70q5xFxMI4D3BpH09Ws1f-ENc,5849
|
|
2
2
|
sycommon/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
3
3
|
sycommon/services.py,sha256=vcO2vbe2U1CA4ykLdH1rnxgqUIouukE-wTRsjRl2kBI,11683
|
|
4
|
-
sycommon/config/Config.py,sha256=
|
|
4
|
+
sycommon/config/Config.py,sha256=L4vlGsVFL1ZHEULxvE8-VyLF-wDBuOMZGmWXIldqfn8,4014
|
|
5
5
|
sycommon/config/DatabaseConfig.py,sha256=ILiUuYT9_xJZE2W-RYuC3JCt_YLKc1sbH13-MHIOPhg,804
|
|
6
6
|
sycommon/config/EmbeddingConfig.py,sha256=gPKwiDYbeu1GpdIZXMmgqM7JqBIzCXi0yYuGRLZooMI,362
|
|
7
7
|
sycommon/config/LLMConfig.py,sha256=yU-aIqePIeF6msfRVEtGq7SXZVDfHyTi6JduKjhMO_4,371
|
|
8
|
+
sycommon/config/LangfuseConfig.py,sha256=t2LulAtnMUvIINOKHXNWlT5PtgNb7IuaHURjWlbma38,370
|
|
8
9
|
sycommon/config/MQConfig.py,sha256=_RDcmIdyWKjmgM5ZnriOoI-DpaxgXs7CD0awdAD6z88,252
|
|
9
10
|
sycommon/config/RerankerConfig.py,sha256=35sVwzus2IscvTHnCG63Orl2pC-pMsrVi6wAGDmOH3U,341
|
|
10
11
|
sycommon/config/SentryConfig.py,sha256=OsLb3G9lTsCSZ7tWkcXWJHmvfILQopBxje5pjnkFJfo,320
|
|
@@ -19,7 +20,7 @@ sycommon/health/metrics.py,sha256=fHqO73JuhoZkNPR-xIlxieXiTCvttq-kG-tvxag1s1s,26
|
|
|
19
20
|
sycommon/health/ping.py,sha256=FTlnIKk5y1mPfS1ZGOeT5IM_2udF5aqVLubEtuBp18M,250
|
|
20
21
|
sycommon/llm/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
21
22
|
sycommon/llm/embedding.py,sha256=HknwDqXmRQcAZ8-6d8wZ6n7Bv7HtxTajDt1vvzHGeFQ,8411
|
|
22
|
-
sycommon/llm/get_llm.py,sha256=
|
|
23
|
+
sycommon/llm/get_llm.py,sha256=vPwGNm2DaF4-ZzhfRUcDFJY756IK93pvGjAnuhP_Fec,10179
|
|
23
24
|
sycommon/llm/llm_logger.py,sha256=n4UeNy_-g4oHQOsw-VUzF4uo3JVRLtxaMp1FcI8FiEo,5437
|
|
24
25
|
sycommon/llm/llm_tokens.py,sha256=-udDyFcmyzx6UAwIi6_d_wwI5kMd5w0-WcS2soVPQxg,4309
|
|
25
26
|
sycommon/logging/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
@@ -78,8 +79,8 @@ sycommon/tools/env.py,sha256=Ah-tBwG2C0_hwLGFebVQgKdWWXCjTzBuF23gCkLHYy4,2437
|
|
|
78
79
|
sycommon/tools/merge_headers.py,sha256=HV_i52Q-9se3SP8qh7ZGYl8bP7Fxtal4CGVkyMwEdM8,4373
|
|
79
80
|
sycommon/tools/snowflake.py,sha256=lVEe5mNCOgz5OqGQpf5_nXaGnRJlI2STX2s-ppTtanA,11947
|
|
80
81
|
sycommon/tools/timing.py,sha256=OiiE7P07lRoMzX9kzb8sZU9cDb0zNnqIlY5pWqHcnkY,2064
|
|
81
|
-
sycommon_python_lib-0.1.
|
|
82
|
-
sycommon_python_lib-0.1.
|
|
83
|
-
sycommon_python_lib-0.1.
|
|
84
|
-
sycommon_python_lib-0.1.
|
|
85
|
-
sycommon_python_lib-0.1.
|
|
82
|
+
sycommon_python_lib-0.1.56b14.dist-info/METADATA,sha256=6ctE6A1k94pk7BDDaUWojL_gBLx8dodryWjZjLOa0yU,7302
|
|
83
|
+
sycommon_python_lib-0.1.56b14.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
84
|
+
sycommon_python_lib-0.1.56b14.dist-info/entry_points.txt,sha256=q_h2nbvhhmdnsOUZEIwpuoDjaNfBF9XqppDEmQn9d_A,46
|
|
85
|
+
sycommon_python_lib-0.1.56b14.dist-info/top_level.txt,sha256=98CJ-cyM2WIKxLz-Pf0AitWLhJyrfXvyY8slwjTXNuc,17
|
|
86
|
+
sycommon_python_lib-0.1.56b14.dist-info/RECORD,,
|
|
File without changes
|
{sycommon_python_lib-0.1.56b13.dist-info → sycommon_python_lib-0.1.56b14.dist-info}/entry_points.txt
RENAMED
|
File without changes
|
{sycommon_python_lib-0.1.56b13.dist-info → sycommon_python_lib-0.1.56b14.dist-info}/top_level.txt
RENAMED
|
File without changes
|