sycommon-python-lib 0.1.56b12__tar.gz → 0.1.56b14__tar.gz
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_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/PKG-INFO +2 -1
- {sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/pyproject.toml +2 -1
- {sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/config/Config.py +7 -0
- sycommon_python_lib-0.1.56b14/src/sycommon/config/LangfuseConfig.py +15 -0
- {sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/llm/embedding.py +78 -23
- {sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/llm/get_llm.py +19 -1
- {sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon_python_lib.egg-info/PKG-INFO +2 -1
- {sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon_python_lib.egg-info/SOURCES.txt +1 -0
- {sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon_python_lib.egg-info/requires.txt +1 -0
- {sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/README.md +0 -0
- {sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/setup.cfg +0 -0
- {sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/command/cli.py +0 -0
- {sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/__init__.py +0 -0
- {sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/config/DatabaseConfig.py +0 -0
- {sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/config/EmbeddingConfig.py +0 -0
- {sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/config/LLMConfig.py +0 -0
- {sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/config/MQConfig.py +0 -0
- {sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/config/RerankerConfig.py +0 -0
- {sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/config/SentryConfig.py +0 -0
- {sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/config/__init__.py +0 -0
- {sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/database/async_base_db_service.py +0 -0
- {sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/database/async_database_service.py +0 -0
- {sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/database/base_db_service.py +0 -0
- {sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/database/database_service.py +0 -0
- {sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/health/__init__.py +0 -0
- {sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/health/health_check.py +0 -0
- {sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/health/metrics.py +0 -0
- {sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/health/ping.py +0 -0
- {sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/llm/__init__.py +0 -0
- {sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/llm/llm_logger.py +0 -0
- {sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/llm/llm_tokens.py +0 -0
- {sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/logging/__init__.py +0 -0
- {sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/logging/async_sql_logger.py +0 -0
- {sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/logging/kafka_log.py +0 -0
- {sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/logging/logger_levels.py +0 -0
- {sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/logging/logger_wrapper.py +0 -0
- {sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/logging/sql_logger.py +0 -0
- {sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/middleware/__init__.py +0 -0
- {sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/middleware/context.py +0 -0
- {sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/middleware/cors.py +0 -0
- {sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/middleware/docs.py +0 -0
- {sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/middleware/exception.py +0 -0
- {sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/middleware/middleware.py +0 -0
- {sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/middleware/monitor_memory.py +0 -0
- {sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/middleware/mq.py +0 -0
- {sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/middleware/timeout.py +0 -0
- {sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/middleware/traceid.py +0 -0
- {sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/models/__init__.py +0 -0
- {sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/models/base_http.py +0 -0
- {sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/models/log.py +0 -0
- {sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/models/mqlistener_config.py +0 -0
- {sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/models/mqmsg_model.py +0 -0
- {sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/models/mqsend_config.py +0 -0
- {sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/models/sso_user.py +0 -0
- {sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/notice/__init__.py +0 -0
- {sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/notice/uvicorn_monitor.py +0 -0
- {sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/rabbitmq/rabbitmq_client.py +0 -0
- {sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/rabbitmq/rabbitmq_pool.py +0 -0
- {sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/rabbitmq/rabbitmq_service.py +0 -0
- {sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/rabbitmq/rabbitmq_service_client_manager.py +0 -0
- {sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/rabbitmq/rabbitmq_service_connection_monitor.py +0 -0
- {sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/rabbitmq/rabbitmq_service_consumer_manager.py +0 -0
- {sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/rabbitmq/rabbitmq_service_core.py +0 -0
- {sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/rabbitmq/rabbitmq_service_producer_manager.py +0 -0
- {sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/sentry/__init__.py +0 -0
- {sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/sentry/sy_sentry.py +0 -0
- {sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/services.py +0 -0
- {sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/sse/__init__.py +0 -0
- {sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/sse/event.py +0 -0
- {sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/sse/sse.py +0 -0
- {sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/synacos/__init__.py +0 -0
- {sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/synacos/example.py +0 -0
- {sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/synacos/example2.py +0 -0
- {sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/synacos/feign.py +0 -0
- {sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/synacos/feign_client.py +0 -0
- {sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/synacos/nacos_client_base.py +0 -0
- {sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/synacos/nacos_config_manager.py +0 -0
- {sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/synacos/nacos_heartbeat_manager.py +0 -0
- {sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/synacos/nacos_service.py +0 -0
- {sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/synacos/nacos_service_discovery.py +0 -0
- {sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/synacos/nacos_service_registration.py +0 -0
- {sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/synacos/param.py +0 -0
- {sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/tools/__init__.py +0 -0
- {sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/tools/docs.py +0 -0
- {sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/tools/env.py +0 -0
- {sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/tools/merge_headers.py +0 -0
- {sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/tools/snowflake.py +0 -0
- {sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/tools/timing.py +0 -0
- {sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon_python_lib.egg-info/dependency_links.txt +0 -0
- {sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon_python_lib.egg-info/entry_points.txt +0 -0
- {sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon_python_lib.egg-info/top_level.txt +0 -0
|
@@ -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,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "sycommon-python-lib"
|
|
3
|
-
version = "0.1.56-
|
|
3
|
+
version = "0.1.56-beta14"
|
|
4
4
|
description = "Add your description here"
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
requires-python = ">=3.11"
|
|
@@ -14,6 +14,7 @@ dependencies = [
|
|
|
14
14
|
"langchain>=1.2.0",
|
|
15
15
|
"langchain-core>=1.2.6",
|
|
16
16
|
"langchain-openai>=1.1.6",
|
|
17
|
+
"langfuse>=3.11.2",
|
|
17
18
|
"langgraph>=1.0.5",
|
|
18
19
|
"loguru>=0.7.3",
|
|
19
20
|
"mysql-connector-python>=9.5.0",
|
{sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/config/Config.py
RENAMED
|
@@ -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_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/llm/embedding.py
RENAMED
|
@@ -25,15 +25,21 @@ class Embedding(metaclass=SingletonMeta):
|
|
|
25
25
|
|
|
26
26
|
# 并发信号量
|
|
27
27
|
self.semaphore = asyncio.Semaphore(self.max_concurrency)
|
|
28
|
+
# 全局默认超时:永不超时(None)
|
|
29
|
+
self.default_timeout = aiohttp.ClientTimeout(total=None)
|
|
28
30
|
|
|
29
31
|
async def _get_embeddings_http_async(
|
|
30
32
|
self,
|
|
31
33
|
input: Union[str, List[str]],
|
|
32
34
|
encoding_format: str = None,
|
|
33
35
|
model: str = None,
|
|
36
|
+
timeout: aiohttp.ClientTimeout = None,
|
|
34
37
|
**kwargs
|
|
35
38
|
):
|
|
36
39
|
async with self.semaphore:
|
|
40
|
+
# 优先使用传入的超时,无则用全局默认
|
|
41
|
+
request_timeout = timeout or self.default_timeout
|
|
42
|
+
|
|
37
43
|
# 优先使用传入的模型名,无则用默认值
|
|
38
44
|
target_model = model or self.default_embedding_model
|
|
39
45
|
target_base_url = EmbeddingConfig.from_config(target_model).baseUrl
|
|
@@ -46,14 +52,23 @@ class Embedding(metaclass=SingletonMeta):
|
|
|
46
52
|
}
|
|
47
53
|
request_body.update(kwargs)
|
|
48
54
|
|
|
49
|
-
|
|
50
|
-
async with
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
55
|
+
try:
|
|
56
|
+
async with aiohttp.ClientSession(timeout=request_timeout) as session:
|
|
57
|
+
async with session.post(url, json=request_body) as response:
|
|
58
|
+
if response.status != 200:
|
|
59
|
+
error_detail = await response.text()
|
|
60
|
+
SYLogger.error(
|
|
61
|
+
f"Embedding request failed (model: {target_model}): {error_detail}")
|
|
62
|
+
return None
|
|
63
|
+
return await response.json()
|
|
64
|
+
except asyncio.TimeoutError:
|
|
65
|
+
SYLogger.error(
|
|
66
|
+
f"Embedding request timeout (model: {target_model})")
|
|
67
|
+
return None
|
|
68
|
+
except Exception as e:
|
|
69
|
+
SYLogger.error(
|
|
70
|
+
f"Embedding request unexpected error (model: {target_model}): {str(e)}")
|
|
71
|
+
return None
|
|
57
72
|
|
|
58
73
|
async def _get_reranker_http_async(
|
|
59
74
|
self,
|
|
@@ -64,9 +79,13 @@ class Embedding(metaclass=SingletonMeta):
|
|
|
64
79
|
max_chunks_per_doc: Optional[int] = None,
|
|
65
80
|
return_documents: Optional[bool] = True,
|
|
66
81
|
return_len: Optional[bool] = True,
|
|
82
|
+
timeout: aiohttp.ClientTimeout = None,
|
|
67
83
|
**kwargs
|
|
68
84
|
):
|
|
69
85
|
async with self.semaphore:
|
|
86
|
+
# 优先使用传入的超时,无则用全局默认
|
|
87
|
+
request_timeout = timeout or self.default_timeout
|
|
88
|
+
|
|
70
89
|
# 优先使用传入的模型名,无则用默认值
|
|
71
90
|
target_model = model or self.default_reranker_model
|
|
72
91
|
target_base_url = RerankerConfig.from_config(target_model).baseUrl
|
|
@@ -84,19 +103,29 @@ class Embedding(metaclass=SingletonMeta):
|
|
|
84
103
|
}
|
|
85
104
|
request_body.update(kwargs)
|
|
86
105
|
|
|
87
|
-
|
|
88
|
-
async with
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
106
|
+
try:
|
|
107
|
+
async with aiohttp.ClientSession(timeout=request_timeout) as session:
|
|
108
|
+
async with session.post(url, json=request_body) as response:
|
|
109
|
+
if response.status != 200:
|
|
110
|
+
error_detail = await response.text()
|
|
111
|
+
SYLogger.error(
|
|
112
|
+
f"Rerank request failed (model: {target_model}): {error_detail}")
|
|
113
|
+
return None
|
|
114
|
+
return await response.json()
|
|
115
|
+
except asyncio.TimeoutError:
|
|
116
|
+
SYLogger.error(
|
|
117
|
+
f"Rerank request timeout (model: {target_model})")
|
|
118
|
+
return None
|
|
119
|
+
except Exception as e:
|
|
120
|
+
SYLogger.error(
|
|
121
|
+
f"Rerank request unexpected error (model: {target_model}): {str(e)}")
|
|
122
|
+
return None
|
|
95
123
|
|
|
96
124
|
async def get_embeddings(
|
|
97
125
|
self,
|
|
98
126
|
corpus: List[str],
|
|
99
|
-
model: str = None
|
|
127
|
+
model: str = None,
|
|
128
|
+
timeout: Optional[Union[int, float]] = None
|
|
100
129
|
):
|
|
101
130
|
"""
|
|
102
131
|
获取语料库的嵌入向量,结果顺序与输入语料库顺序一致
|
|
@@ -104,12 +133,24 @@ class Embedding(metaclass=SingletonMeta):
|
|
|
104
133
|
Args:
|
|
105
134
|
corpus: 待生成嵌入向量的文本列表
|
|
106
135
|
model: 可选,指定使用的embedding模型名称,默认使用bge-large-zh-v1.5
|
|
136
|
+
timeout: 可选,超时时间(秒):
|
|
137
|
+
- 传int/float:表示总超时时间(秒)
|
|
138
|
+
- 不传/None:使用默认永不超时配置
|
|
107
139
|
"""
|
|
140
|
+
request_timeout = None
|
|
141
|
+
if timeout is not None:
|
|
142
|
+
if isinstance(timeout, (int, float)):
|
|
143
|
+
request_timeout = aiohttp.ClientTimeout(total=timeout)
|
|
144
|
+
else:
|
|
145
|
+
SYLogger.warning(
|
|
146
|
+
f"Invalid timeout type: {type(timeout)}, must be int/float, use default timeout")
|
|
147
|
+
|
|
108
148
|
SYLogger.info(
|
|
109
|
-
f"Requesting embeddings for corpus: {corpus} (model: {model or self.default_embedding_model}, max_concurrency: {self.max_concurrency})")
|
|
110
|
-
|
|
149
|
+
f"Requesting embeddings for corpus: {corpus} (model: {model or self.default_embedding_model}, max_concurrency: {self.max_concurrency}, timeout: {timeout or 'None'})")
|
|
150
|
+
|
|
151
|
+
# 给每个异步任务传入模型名称和超时配置
|
|
111
152
|
tasks = [self._get_embeddings_http_async(
|
|
112
|
-
text, model=model) for text in corpus]
|
|
153
|
+
text, model=model, timeout=request_timeout) for text in corpus]
|
|
113
154
|
results = await asyncio.gather(*tasks)
|
|
114
155
|
|
|
115
156
|
vectors = []
|
|
@@ -131,7 +172,8 @@ class Embedding(metaclass=SingletonMeta):
|
|
|
131
172
|
self,
|
|
132
173
|
top_results: List[str],
|
|
133
174
|
query: str,
|
|
134
|
-
model: str = None
|
|
175
|
+
model: str = None,
|
|
176
|
+
timeout: Optional[Union[int, float]] = None
|
|
135
177
|
):
|
|
136
178
|
"""
|
|
137
179
|
对搜索结果进行重排序
|
|
@@ -140,10 +182,23 @@ class Embedding(metaclass=SingletonMeta):
|
|
|
140
182
|
top_results: 待重排序的文本列表
|
|
141
183
|
query: 排序参考的查询语句
|
|
142
184
|
model: 可选,指定使用的reranker模型名称,默认使用bge-reranker-large
|
|
185
|
+
timeout: 可选,超时时间(秒):
|
|
186
|
+
- 传int/float:表示总超时时间(秒)
|
|
187
|
+
- 不传/None:使用默认永不超时配置
|
|
143
188
|
"""
|
|
189
|
+
request_timeout = None
|
|
190
|
+
if timeout is not None:
|
|
191
|
+
if isinstance(timeout, (int, float)):
|
|
192
|
+
request_timeout = aiohttp.ClientTimeout(total=timeout)
|
|
193
|
+
else:
|
|
194
|
+
SYLogger.warning(
|
|
195
|
+
f"Invalid timeout type: {type(timeout)}, must be int/float, use default timeout")
|
|
196
|
+
|
|
144
197
|
SYLogger.info(
|
|
145
|
-
f"Requesting reranker for top_results: {top_results} (model: {model or self.default_reranker_model}, max_concurrency: {self.max_concurrency})")
|
|
146
|
-
|
|
198
|
+
f"Requesting reranker for top_results: {top_results} (model: {model or self.default_reranker_model}, max_concurrency: {self.max_concurrency}, timeout: {timeout or 'None'})")
|
|
199
|
+
|
|
200
|
+
data = await self._get_reranker_http_async(
|
|
201
|
+
top_results, query, model=model, timeout=request_timeout)
|
|
147
202
|
SYLogger.info(
|
|
148
203
|
f"Reranker for top_results: {top_results} completed (model: {model or self.default_reranker_model})")
|
|
149
204
|
return data
|
|
@@ -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:
|
|
@@ -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
|
|
@@ -7,6 +7,7 @@ src/sycommon/config/Config.py
|
|
|
7
7
|
src/sycommon/config/DatabaseConfig.py
|
|
8
8
|
src/sycommon/config/EmbeddingConfig.py
|
|
9
9
|
src/sycommon/config/LLMConfig.py
|
|
10
|
+
src/sycommon/config/LangfuseConfig.py
|
|
10
11
|
src/sycommon/config/MQConfig.py
|
|
11
12
|
src/sycommon/config/RerankerConfig.py
|
|
12
13
|
src/sycommon/config/SentryConfig.py
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/config/LLMConfig.py
RENAMED
|
File without changes
|
{sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/config/MQConfig.py
RENAMED
|
File without changes
|
|
File without changes
|
{sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/config/SentryConfig.py
RENAMED
|
File without changes
|
{sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/config/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/health/__init__.py
RENAMED
|
File without changes
|
{sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/health/health_check.py
RENAMED
|
File without changes
|
{sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/health/metrics.py
RENAMED
|
File without changes
|
|
File without changes
|
{sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/llm/__init__.py
RENAMED
|
File without changes
|
{sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/llm/llm_logger.py
RENAMED
|
File without changes
|
{sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/llm/llm_tokens.py
RENAMED
|
File without changes
|
{sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/logging/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
{sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/logging/kafka_log.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/logging/sql_logger.py
RENAMED
|
File without changes
|
{sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/middleware/__init__.py
RENAMED
|
File without changes
|
{sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/middleware/context.py
RENAMED
|
File without changes
|
{sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/middleware/cors.py
RENAMED
|
File without changes
|
{sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/middleware/docs.py
RENAMED
|
File without changes
|
{sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/middleware/exception.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/middleware/mq.py
RENAMED
|
File without changes
|
{sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/middleware/timeout.py
RENAMED
|
File without changes
|
{sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/middleware/traceid.py
RENAMED
|
File without changes
|
{sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/models/__init__.py
RENAMED
|
File without changes
|
{sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/models/base_http.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/models/mqmsg_model.py
RENAMED
|
File without changes
|
{sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/models/mqsend_config.py
RENAMED
|
File without changes
|
{sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/models/sso_user.py
RENAMED
|
File without changes
|
{sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/notice/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/sentry/__init__.py
RENAMED
|
File without changes
|
{sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/sentry/sy_sentry.py
RENAMED
|
File without changes
|
|
File without changes
|
{sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/sse/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/synacos/__init__.py
RENAMED
|
File without changes
|
{sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/synacos/example.py
RENAMED
|
File without changes
|
{sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/synacos/example2.py
RENAMED
|
File without changes
|
{sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/synacos/feign.py
RENAMED
|
File without changes
|
{sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/synacos/feign_client.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/synacos/param.py
RENAMED
|
File without changes
|
{sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/tools/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/tools/merge_headers.py
RENAMED
|
File without changes
|
{sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/tools/snowflake.py
RENAMED
|
File without changes
|
{sycommon_python_lib-0.1.56b12 → sycommon_python_lib-0.1.56b14}/src/sycommon/tools/timing.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|