sdpy-kit 0.3.1__tar.gz → 0.4.0__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.
- {sdpy_kit-0.3.1 → sdpy_kit-0.4.0}/.gitignore +1 -3
- sdpy_kit-0.3.1/README.md → sdpy_kit-0.4.0/PKG-INFO +90 -138
- sdpy_kit-0.3.1/PKG-INFO → sdpy_kit-0.4.0/README.md +18 -216
- {sdpy_kit-0.3.1 → sdpy_kit-0.4.0}/kit/__init__.py +1 -1
- {sdpy_kit-0.3.1 → sdpy_kit-0.4.0}/kit/config/kit_config.py +0 -32
- sdpy_kit-0.4.0/kit/crawl/__init__.py +63 -0
- {sdpy_kit-0.3.1/kit → sdpy_kit-0.4.0/kit/crawl}/article_models.py +2 -2
- {sdpy_kit-0.3.1/kit → sdpy_kit-0.4.0/kit/crawl}/web_article_kit.py +8 -8
- {sdpy_kit-0.3.1/kit → sdpy_kit-0.4.0/kit/crawl}/wx_article_kit.py +5 -5
- {sdpy_kit-0.3.1 → sdpy_kit-0.4.0}/kit/db/mysql_kit.py +1 -1
- {sdpy_kit-0.3.1 → sdpy_kit-0.4.0}/pyproject.toml +3 -9
- sdpy_kit-0.3.1/kit/mcp_kit.py +0 -547
- sdpy_kit-0.3.1/kit/zvec_kit.py +0 -671
- {sdpy_kit-0.3.1 → sdpy_kit-0.4.0}/kit/ai/__init__.py +0 -0
- {sdpy_kit-0.3.1 → sdpy_kit-0.4.0}/kit/ai/base_service.py +0 -0
- {sdpy_kit-0.3.1 → sdpy_kit-0.4.0}/kit/ai/chat_service.py +0 -0
- {sdpy_kit-0.3.1 → sdpy_kit-0.4.0}/kit/ai/embedding_service.py +0 -0
- {sdpy_kit-0.3.1 → sdpy_kit-0.4.0}/kit/ai/exceptions.py +0 -0
- {sdpy_kit-0.3.1 → sdpy_kit-0.4.0}/kit/ai/failover.py +0 -0
- {sdpy_kit-0.3.1 → sdpy_kit-0.4.0}/kit/ai/image_service.py +0 -0
- {sdpy_kit-0.3.1 → sdpy_kit-0.4.0}/kit/ai/model_builder.py +0 -0
- {sdpy_kit-0.3.1 → sdpy_kit-0.4.0}/kit/ai/model_client.py +0 -0
- {sdpy_kit-0.3.1 → sdpy_kit-0.4.0}/kit/ai/pool.py +0 -0
- {sdpy_kit-0.3.1 → sdpy_kit-0.4.0}/kit/ai/profiles.py +0 -0
- {sdpy_kit-0.3.1 → sdpy_kit-0.4.0}/kit/ai/rerank_service.py +0 -0
- {sdpy_kit-0.3.1 → sdpy_kit-0.4.0}/kit/ai/runner.py +0 -0
- {sdpy_kit-0.3.1 → sdpy_kit-0.4.0}/kit/ai/types.py +0 -0
- {sdpy_kit-0.3.1 → sdpy_kit-0.4.0}/kit/anydoc_kit.py +0 -0
- {sdpy_kit-0.3.1 → sdpy_kit-0.4.0}/kit/common_kit.py +0 -0
- {sdpy_kit-0.3.1 → sdpy_kit-0.4.0}/kit/config/__init__.py +0 -0
- {sdpy_kit-0.3.1 → sdpy_kit-0.4.0}/kit/config/log_config.py +0 -0
- {sdpy_kit-0.3.1 → sdpy_kit-0.4.0}/kit/db/__init__.py +0 -0
- {sdpy_kit-0.3.1 → sdpy_kit-0.4.0}/kit/db/base_db_kit.py +0 -0
- {sdpy_kit-0.3.1 → sdpy_kit-0.4.0}/kit/db/crud.py +0 -0
- {sdpy_kit-0.3.1 → sdpy_kit-0.4.0}/kit/db/engine.py +0 -0
- {sdpy_kit-0.3.1 → sdpy_kit-0.4.0}/kit/db/exceptions.py +0 -0
- {sdpy_kit-0.3.1 → sdpy_kit-0.4.0}/kit/db/models/__init__.py +0 -0
- {sdpy_kit-0.3.1 → sdpy_kit-0.4.0}/kit/db/models/base.py +0 -0
- {sdpy_kit-0.3.1 → sdpy_kit-0.4.0}/kit/db/pg_kit.py +0 -0
- {sdpy_kit-0.3.1 → sdpy_kit-0.4.0}/kit/db/query.py +0 -0
- {sdpy_kit-0.3.1 → sdpy_kit-0.4.0}/kit/db/session.py +0 -0
- {sdpy_kit-0.3.1 → sdpy_kit-0.4.0}/kit/db/sqlite_kit.py +0 -0
- {sdpy_kit-0.3.1 → sdpy_kit-0.4.0}/kit/db/transaction.py +0 -0
- {sdpy_kit-0.3.1 → sdpy_kit-0.4.0}/kit/docx_kit.py +0 -0
- {sdpy_kit-0.3.1 → sdpy_kit-0.4.0}/kit/file_kit.py +0 -0
- {sdpy_kit-0.3.1 → sdpy_kit-0.4.0}/kit/laya_kit.py +0 -0
- {sdpy_kit-0.3.1 → sdpy_kit-0.4.0}/kit/marker_kit.py +0 -0
- {sdpy_kit-0.3.1 → sdpy_kit-0.4.0}/kit/md2doc_kit.py +0 -0
- {sdpy_kit-0.3.1 → sdpy_kit-0.4.0}/kit/mineru_kit.py +0 -0
- {sdpy_kit-0.3.1 → sdpy_kit-0.4.0}/kit/redis_kit.py +0 -0
|
@@ -55,12 +55,10 @@ target/
|
|
|
55
55
|
Thumbs.db
|
|
56
56
|
Servers
|
|
57
57
|
.metadata
|
|
58
|
-
# 根目录 data/ 运行时数据(
|
|
58
|
+
# 根目录 data/ 运行时数据(SQLite 测试库等,不入库)
|
|
59
59
|
data/
|
|
60
60
|
# AI 文生图 e2e 测试产物(生成的海报图片,不入库)
|
|
61
61
|
tests/image/
|
|
62
|
-
# AMiner 检索测试产物(md 报告,不入库)
|
|
63
|
-
tests/aminer/
|
|
64
62
|
# SQLite 测试库(运行时生成,不入库)
|
|
65
63
|
metadata_log.db
|
|
66
64
|
upload
|
|
@@ -1,11 +1,82 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: sdpy-kit
|
|
3
|
+
Version: 0.4.0
|
|
4
|
+
Summary: SDPY Kit——统一数据库访问层(PG/MySQL/SQLite)与 AI/Redis/文件/文档/向量工具集
|
|
5
|
+
Author-email: Clark <changhongyuan@126.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Keywords: ai,kit,mysql,postgresql,redis,sdpy,sqlalchemy,sqlite,sqlmodel,向量检索,工具集,开发工具,数据库
|
|
8
|
+
Classifier: Development Status :: 4 - Beta
|
|
9
|
+
Classifier: Intended Audience :: Developers
|
|
10
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
11
|
+
Classifier: Natural Language :: Chinese (Simplified)
|
|
12
|
+
Classifier: Operating System :: OS Independent
|
|
13
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
16
|
+
Classifier: Topic :: Database
|
|
17
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
18
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
19
|
+
Requires-Python: >=3.13
|
|
20
|
+
Requires-Dist: pydantic-settings>=2.15.0
|
|
21
|
+
Requires-Dist: pydantic>=2.14.1
|
|
22
|
+
Requires-Dist: sqlalchemy~=2.0.54
|
|
23
|
+
Requires-Dist: sqlmodel>=0.0.48
|
|
24
|
+
Provides-Extra: ai
|
|
25
|
+
Requires-Dist: httpx>=0.28.1; extra == 'ai'
|
|
26
|
+
Requires-Dist: python-dotenv>=1.2.4; extra == 'ai'
|
|
27
|
+
Provides-Extra: all
|
|
28
|
+
Requires-Dist: docxtpl>=0.20.2; extra == 'all'
|
|
29
|
+
Requires-Dist: firecrawl-anydoc>=0.2.4; extra == 'all'
|
|
30
|
+
Requires-Dist: httpx>=0.28.1; extra == 'all'
|
|
31
|
+
Requires-Dist: huggingface-hub<2,>=1.5; extra == 'all'
|
|
32
|
+
Requires-Dist: laya>=0.4.6; extra == 'all'
|
|
33
|
+
Requires-Dist: markdown-it-py>=4.2.0; extra == 'all'
|
|
34
|
+
Requires-Dist: marker-pdf[full]>=2.0.0; extra == 'all'
|
|
35
|
+
Requires-Dist: numpy>=2.5.4; extra == 'all'
|
|
36
|
+
Requires-Dist: pikepdf>=10.17.0; extra == 'all'
|
|
37
|
+
Requires-Dist: pimd[pdfa]>=2.2.5; extra == 'all'
|
|
38
|
+
Requires-Dist: psycopg2-binary>=2.9.13; extra == 'all'
|
|
39
|
+
Requires-Dist: pymysql>=1.2.3; extra == 'all'
|
|
40
|
+
Requires-Dist: python-dotenv>=1.2.4; extra == 'all'
|
|
41
|
+
Requires-Dist: redis>=8.1.0; extra == 'all'
|
|
42
|
+
Requires-Dist: requests>=2.34.2; extra == 'all'
|
|
43
|
+
Requires-Dist: sqliteai-vector>=1.1.2; extra == 'all'
|
|
44
|
+
Requires-Dist: trafilatura>=2.3.1; extra == 'all'
|
|
45
|
+
Provides-Extra: anydoc
|
|
46
|
+
Requires-Dist: firecrawl-anydoc>=0.2.4; extra == 'anydoc'
|
|
47
|
+
Requires-Dist: pikepdf>=10.17.0; extra == 'anydoc'
|
|
48
|
+
Provides-Extra: docx
|
|
49
|
+
Requires-Dist: docxtpl>=0.20.2; extra == 'docx'
|
|
50
|
+
Provides-Extra: laya
|
|
51
|
+
Requires-Dist: huggingface-hub<2,>=1.5; extra == 'laya'
|
|
52
|
+
Requires-Dist: laya>=0.4.6; extra == 'laya'
|
|
53
|
+
Provides-Extra: marker
|
|
54
|
+
Requires-Dist: marker-pdf[full]>=2.0.0; extra == 'marker'
|
|
55
|
+
Provides-Extra: md2doc
|
|
56
|
+
Requires-Dist: markdown-it-py>=4.2.0; extra == 'md2doc'
|
|
57
|
+
Requires-Dist: pimd[pdfa]>=2.2.5; extra == 'md2doc'
|
|
58
|
+
Provides-Extra: mineru
|
|
59
|
+
Requires-Dist: requests>=2.34.2; extra == 'mineru'
|
|
60
|
+
Provides-Extra: mysql
|
|
61
|
+
Requires-Dist: pymysql>=1.2.3; extra == 'mysql'
|
|
62
|
+
Provides-Extra: pg
|
|
63
|
+
Requires-Dist: psycopg2-binary>=2.9.13; extra == 'pg'
|
|
64
|
+
Provides-Extra: redis
|
|
65
|
+
Requires-Dist: redis>=8.1.0; extra == 'redis'
|
|
66
|
+
Provides-Extra: sqliteai
|
|
67
|
+
Requires-Dist: numpy>=2.5.4; extra == 'sqliteai'
|
|
68
|
+
Requires-Dist: sqliteai-vector>=1.1.2; extra == 'sqliteai'
|
|
69
|
+
Provides-Extra: web-article
|
|
70
|
+
Requires-Dist: trafilatura>=2.3.1; extra == 'web-article'
|
|
71
|
+
Description-Content-Type: text/markdown
|
|
72
|
+
|
|
1
73
|
# sdpy-kit
|
|
2
74
|
|
|
3
75
|
SDPY 统一工具集(Kit 体系),供 Python 项目开箱即用:
|
|
4
76
|
|
|
5
77
|
- **统一数据库访问层**:PostgreSQL / MySQL / SQLite,三个 Kit API 完全一致,切换数据库只改一行 import;
|
|
6
78
|
- **AI 多模型服务池**:chat / embedding / rerank / image 四类能力,多厂商候选链 + 故障自动转移;
|
|
7
|
-
-
|
|
8
|
-
- **工具集**:Redis / 文件 / 雪花 ID / 文档互转 / Word 模板填充 / MinerU 解析 / Marker 本地解析(md + images) / Laya 类型化决策 / 向量库 / 微信公众号文章抓取存储 / 通用网页文章抓取存储。
|
|
79
|
+
- **工具集**:Redis / 文件 / 雪花 ID / 文档互转 / Word 模板填充 / MinerU 解析 / Marker 本地解析(md + images) / Laya 类型化决策 / 微信公众号文章抓取存储 / 通用网页文章抓取存储。
|
|
9
80
|
|
|
10
81
|
> 要求 Python 3.13+
|
|
11
82
|
|
|
@@ -16,7 +87,6 @@ SDPY 统一工具集(Kit 体系),供 Python 项目开箱即用:
|
|
|
16
87
|
| `kit.config` | `get_settings` / `get_default_logger` | 配置单例与统一日志 | 无 |
|
|
17
88
|
| `kit.db` | `SQLiteKit` / `PgKit` / `MySqlKit` / `CRUDBase` | 统一 CRUD、原生 SQL、原生表操作、事务、表管理 | `pg` / `mysql` / `sqliteai` |
|
|
18
89
|
| `kit.ai` | `AI`(同步门面)/ 4 个原生异步 Service | 对话 / 向量化 / 重排序 / 文生图 | `ai` |
|
|
19
|
-
| `kit.mcp_kit` | `McpKit` | MCP 工具发现与调用 | `mcp` |
|
|
20
90
|
| `kit.redis_kit` | `RedisKit` | Redis string / hash / list / set / zset | `redis` |
|
|
21
91
|
| `kit.file_kit` | `FileKit` | 文件与目录读写、移动、遍历 | 无 |
|
|
22
92
|
| `kit.common_kit` | `CommonKit` | 雪花 ID、时间戳 ID、时间格式化 | 无 |
|
|
@@ -26,10 +96,9 @@ SDPY 统一工具集(Kit 体系),供 Python 项目开箱即用:
|
|
|
26
96
|
| `kit.mineru_kit` | `MinerUKit` | MinerU 文档解析(精准 + Agent 轻量) | `mineru` |
|
|
27
97
|
| `kit.marker_kit` | `MarkerKit` | 本地文档解析(PDF / 图片 / Office → Markdown + Images) | `marker` |
|
|
28
98
|
| `kit.laya_kit` | `LayaKit` | 类型化决策:choice / score / noul,返回判断结果 + 置信度 | `laya` |
|
|
29
|
-
| `kit.
|
|
30
|
-
| `kit.
|
|
31
|
-
| `kit.
|
|
32
|
-
| `kit.web_article_kit` | `WebArticleKit` | 通用网页文章 → Markdown + 图片转存(**不含微信**,微信请用 `WxArticleKit`;明确支持头条) | `web-article` |
|
|
99
|
+
| `kit.crawl.article_models` | `ArticleInfo` / `ArticleResult` / `SavedOutput` 等 | 文章抓取通用模型(两 `*ArticleKit` 共用,含 `reason` 分类与非致命 `warnings`) | 无 |
|
|
100
|
+
| `kit.crawl.wx_article_kit` | `WxArticleKit` | 微信公众号文章 → Markdown + 图片转存 | 无 |
|
|
101
|
+
| `kit.crawl.web_article_kit` | `WebArticleKit` | 通用网页文章 → Markdown + 图片转存(**不含微信**,微信请用 `WxArticleKit`;明确支持头条) | `web-article` |
|
|
33
102
|
|
|
34
103
|
## 安装
|
|
35
104
|
|
|
@@ -46,9 +115,7 @@ uv add sdpy-kit
|
|
|
46
115
|
| `pg` | PgKit(PostgreSQL 驱动;向量方法另需服务端 pgvector) | `pip install "sdpy-kit[pg]"` |
|
|
47
116
|
| `mysql` | MySqlKit(MySQL 驱动;向量仅存储,需 MySQL 9.x) | `pip install "sdpy-kit[mysql]"` |
|
|
48
117
|
| `sqliteai` | SQLiteKit 向量方法(numpy / sqliteai-vector,SQLite 向量扩展) | `pip install "sdpy-kit[sqliteai]"` |
|
|
49
|
-
| `zvec` | ZvecKit(zvec,阿里独立向量库) | `pip install "sdpy-kit[zvec]"` |
|
|
50
118
|
| `redis` | RedisKit | `pip install "sdpy-kit[redis]"` |
|
|
51
|
-
| `mcp` | McpKit(fastmcp) | `pip install "sdpy-kit[mcp]"` |
|
|
52
119
|
| `ai` | AI 服务池(httpx + python-dotenv) | `pip install "sdpy-kit[ai]"` |
|
|
53
120
|
| `md2doc` | Md2DocKit:Markdown → Word / PDF / HTML(pimd / fpdf2) | `pip install "sdpy-kit[md2doc]"` |
|
|
54
121
|
| `anydoc` | AnyDocKit 文档转 Markdown(firecrawl-anydoc + pikepdf) | `pip install "sdpy-kit[anydoc]"` |
|
|
@@ -89,16 +156,11 @@ SQLITE_DB_PATH=./data/sqlite.db
|
|
|
89
156
|
# REDIS_DB=0
|
|
90
157
|
# REDIS_PASSWORD=
|
|
91
158
|
# FILE_STORAGE_ROOT=./data
|
|
92
|
-
# ZVEC_DATA_DIR=./data/zvec
|
|
93
159
|
|
|
94
160
|
# AI:档案路径 + 你为各模型档案自定的密钥变量名(变量名在 ai_models.json 里声明)
|
|
95
161
|
# AI_MODELS_CONFIG_PATH=./config/ai_models.json
|
|
96
162
|
# SILICONFLOW_API_KEY=sk-xxxxxx
|
|
97
163
|
|
|
98
|
-
# MCP:档案路径 + 你为各服务器自定的 token 变量名(变量名在 mcp_servers.json 里声明)
|
|
99
|
-
# MCP_SERVERS_CONFIG_PATH=./config/mcp_servers.json
|
|
100
|
-
# AMINER_TOKEN=xxxxxx
|
|
101
|
-
|
|
102
164
|
# MinerU(仅精准解析需要 Key,Agent 轻量解析免登录)
|
|
103
165
|
# MINERU_API_KEY=
|
|
104
166
|
|
|
@@ -117,7 +179,7 @@ SQLITE_DB_PATH=./data/sqlite.db
|
|
|
117
179
|
|
|
118
180
|
### 环境变量 ↔ 能力对照表
|
|
119
181
|
|
|
120
|
-
> 表中未出现的模块(`kit.article_models`、`kit.common_kit`、`kit.docx_kit`、`kit.md2doc_kit`、`kit.wx_article_kit`、`kit.web_article_kit`)不读取任何环境变量。
|
|
182
|
+
> 表中未出现的模块(`kit.crawl.article_models`、`kit.common_kit`、`kit.docx_kit`、`kit.md2doc_kit`、`kit.crawl.wx_article_kit`、`kit.crawl.web_article_kit`)不读取任何环境变量。
|
|
121
183
|
|
|
122
184
|
**基础与日志**(影响 `kit.config` 及所有模块的日志输出)
|
|
123
185
|
|
|
@@ -160,18 +222,6 @@ SQLITE_DB_PATH=./data/sqlite.db
|
|
|
160
222
|
|----------|--------|------|
|
|
161
223
|
| `FILE_STORAGE_ROOT` | `./data` | FileKit 全部相对路径的根目录。⚠ 该目录**必须已存在**,否则首次调用抛 `RuntimeError`(根路径不存在) |
|
|
162
224
|
|
|
163
|
-
**向量库** → `kit.zvec_kit`
|
|
164
|
-
|
|
165
|
-
| 环境变量 | 默认值 | 作用 |
|
|
166
|
-
|----------|--------|------|
|
|
167
|
-
| `ZVEC_DATA_DIR` | `./data/zvec` | Collection 根目录 |
|
|
168
|
-
| `ZVEC_DEFAULT_METRIC` | `cosine` | 默认距离度量(`cosine` / `l2` / `ip`) |
|
|
169
|
-
| `ZVEC_QUERY_THREADS` | `None`(自适应) | 查询线程数 |
|
|
170
|
-
| `ZVEC_OPTIMIZE_THREADS` | `None`(自适应) | 索引构建线程数 |
|
|
171
|
-
| `ZVEC_MEMORY_LIMIT_MB` | `None`(自适应) | 内存软上限 |
|
|
172
|
-
| `ZVEC_LOG_DIR` | `./logs/zvec` | zvec 引擎独立日志目录 |
|
|
173
|
-
| `ZVEC_LOG_LEVEL` | `warn` | zvec 引擎日志级别 |
|
|
174
|
-
|
|
175
225
|
**AI** → `kit.ai`
|
|
176
226
|
|
|
177
227
|
| 环境变量 | 默认值 | 作用 |
|
|
@@ -180,14 +230,6 @@ SQLITE_DB_PATH=./data/sqlite.db
|
|
|
180
230
|
| `KIT_AI_CHAIN_TIMEOUT` | 未设置 | 全局整链预算(秒)= 门面同步等待上限。⚠ **不是 `Settings` 字段**,由代码直读 `os.environ`,无类型/范围校验,非法值仅告警后回退 |
|
|
181
231
|
| *(密钥,变量名由档案决定)* | 无 | 名字写在 `ai_models.json` 各档案的 `api_key` 字段(如 `SILICONFLOW_API_KEY`),值放 `.env` 或系统环境变量。未配置的档案会被剔除出候选链;该类型全部未配置则调用失败 |
|
|
182
232
|
|
|
183
|
-
**MCP** → `kit.mcp_kit`
|
|
184
|
-
|
|
185
|
-
| 环境变量 | 默认值 | 作用 |
|
|
186
|
-
|----------|--------|------|
|
|
187
|
-
| `MCP_SERVERS_CONFIG_PATH` | `./config/mcp_servers.json` | 服务器档案位置 |
|
|
188
|
-
| `MCP_CALL_TIMEOUT` | `60`(1–600) | 档案未声明 `timeout` 时的调用超时 |
|
|
189
|
-
| *(令牌,变量名由档案决定)* | 无 | 名字写在 `mcp_servers.json` 各服务器的 `token_env` 字段(如 `AMINER_TOKEN`);档案声明了却两处都未配置时抛 `McpKitError` |
|
|
190
|
-
|
|
191
233
|
**MinerU** → `kit.mineru_kit`
|
|
192
234
|
|
|
193
235
|
| 环境变量 | 默认值 | 作用 |
|
|
@@ -235,7 +277,7 @@ SQLITE_DB_PATH=./data/sqlite.db
|
|
|
235
277
|
|------|----------|----------|--------------|
|
|
236
278
|
| ① Settings 变量 | 固定,kit 定义 | 上表中除 `KIT_AI_CHAIN_TIMEOUT` 与密钥类之外的全部 | pydantic-settings 读 `.env` 与真实环境变量(后者优先),带类型与范围校验,缺失用默认值 |
|
|
237
279
|
| ② 直读变量 | 固定,kit 代码直接读 `os.environ` | `KIT_AI_CHAIN_TIMEOUT` | 无类型校验,非法值告警后回退 |
|
|
238
|
-
| ③ 档案声明变量 | **动态**,名字写在 JSON 里 | AI 的 `api_key
|
|
280
|
+
| ③ 档案声明变量 | **动态**,名字写在 JSON 里 | AI 的 `api_key` | **名字进 JSON、值进 `.env`**——所以档案文件可以安全入库,密钥留在环境里 |
|
|
239
281
|
| ④ 第三方库变量 | 由依赖库定义 | `FIRECRAWL_API_KEY`、`FIRECRAWL_API_URL`(anydoc);`HF_ENDPOINT` / `HF_HUB_DISABLE_XET` / `LLAMA_CPP_BINARY`(marker) | anydoc:kit 只透传 `None`,由其自行回落;marker:kit 在导入前按 `MARKER_*` 配置做 `os.environ.setdefault`(不覆盖显式设置) |
|
|
240
282
|
|
|
241
283
|
### 密钥解析优先级
|
|
@@ -243,7 +285,6 @@ SQLITE_DB_PATH=./data/sqlite.db
|
|
|
243
285
|
| 能力 | 解析顺序 | 全部缺失时 |
|
|
244
286
|
|------|----------|------------|
|
|
245
287
|
| AI | 真实环境变量 > 项目根 `.env`(首次加载档案时经 `load_dotenv(override=False)` 注入 `os.environ`) | 该档案被剔除出候选链;该类型无可用档案则调用报 `AIAggregateError` |
|
|
246
|
-
| MCP | `os.environ` > 项目根 `.env`(kit 自行解析文件) | 抛 `McpKitError` |
|
|
247
288
|
| MinerU | 仅 `Settings`(`.env` / 真实环境变量) | 精准解析接口抛 `MinerUError` |
|
|
248
289
|
|
|
249
290
|
> AI 的 `load_dotenv(override=False)` 表示已存在的真实环境变量不会被 `.env` 覆盖——生产用容器 / 系统环境变量注入时,可以放心保留开发用的 `.env`。
|
|
@@ -252,14 +293,13 @@ SQLITE_DB_PATH=./data/sqlite.db
|
|
|
252
293
|
|
|
253
294
|
| 改动内容 | 生效时机 |
|
|
254
295
|
|----------|----------|
|
|
255
|
-
| `LOG_*`、`DB_*`、`MYSQL_*`、`REDIS_*`、`FILE_STORAGE_ROOT`、`
|
|
296
|
+
| `LOG_*`、`DB_*`、`MYSQL_*`、`REDIS_*`、`FILE_STORAGE_ROOT`、`MINERU_*`、`MARKER_MODE` | `get_settings()` 带 `lru_cache`,进程内首次读取后固定 → **重启进程**(或调用 `AI.reload_config()`,它会顺带清空该缓存) |
|
|
256
297
|
| `MARKER_HF_ENDPOINT` / `MARKER_HF_DISABLE_XET` / `MARKER_LLAMA_CPP_BINARY` | 仅在 `import kit.marker_kit` 时经 `os.environ.setdefault` 应用 → 改动需**重启进程**重新导入模块 |
|
|
257
298
|
| `LAYA_HF_ENDPOINT` / `LAYA_HF_DISABLE_XET` | 仅在 `import kit.laya_kit` 时经 `os.environ.setdefault` 应用 → 改动需**重启进程**重新导入模块 |
|
|
258
299
|
| AI 密钥写在 `.env` 里 | `.env` 只在加载档案时注入一次 → 重启,或 `AI.reload_config(reload_file=True)` |
|
|
259
300
|
| AI 密钥由自己写入 `os.environ` | `AI.reload_config()`(默认 `reload_file=False`,只重读 `os.environ`) |
|
|
260
301
|
| `ai_models.json`(增删档案、换 model) | `AI.reload_config(reload_file=True)` |
|
|
261
302
|
| `KIT_AI_CHAIN_TIMEOUT` | 每次调用现读 `os.environ` → 改 `os.environ` 立即生效;写在 `.env` 里的新值要等下一次档案加载 |
|
|
262
|
-
| MCP token | 每次调用现读 `os.environ` 并回退解析 `.env` → **改 `.env` 立即生效,无需重启** |
|
|
263
303
|
|
|
264
304
|
---
|
|
265
305
|
|
|
@@ -653,7 +693,7 @@ page = qb.paginate(page=1, per_page=20) # {"items", "total", ...}
|
|
|
653
693
|
## kit.ai —— AI 多模型服务池
|
|
654
694
|
|
|
655
695
|
安装:`pip install "sdpy-kit[ai]"`
|
|
656
|
-
档案:项目根 `config/ai_models.json`(见文末「AI
|
|
696
|
+
档案:项目根 `config/ai_models.json`(见文末「AI 档案文件」)
|
|
657
697
|
|
|
658
698
|
### 1. 同步门面 `AI`(推荐)
|
|
659
699
|
|
|
@@ -733,46 +773,6 @@ from kit.ai.exceptions import (
|
|
|
733
773
|
| `AIAggregateError` | 全部候选失败或整链预算耗尽;`tried`、`statuses`、`last_error`、`budget_exhausted` |
|
|
734
774
|
| `AIResponseError` | 响应结构解析失败、流式数据无法解析 |
|
|
735
775
|
|
|
736
|
-
---
|
|
737
|
-
|
|
738
|
-
## kit.mcp_kit —— 通用 MCP 客户端
|
|
739
|
-
|
|
740
|
-
安装:`pip install "sdpy-kit[mcp]"`
|
|
741
|
-
档案:项目根 `config/mcp_servers.json`;token 值放 `.env`(档案里只写环境变量名)
|
|
742
|
-
|
|
743
|
-
```python
|
|
744
|
-
from kit.mcp_kit import McpKit
|
|
745
|
-
|
|
746
|
-
tools = McpKit.list_tools("aminer") # [{name, description}]
|
|
747
|
-
result = McpKit.call_tool("search_paper_by_title", {"title": "水声通信", "size": 10})
|
|
748
|
-
print(result.data, result.elapsed_ms)
|
|
749
|
-
|
|
750
|
-
# 直连临时服务器(不经档案)
|
|
751
|
-
r = McpKit.call_tool_url("https://example.com/mcp", "query", {}, token="...")
|
|
752
|
-
|
|
753
|
-
# 异步环境 / 一次握手复用多次调用
|
|
754
|
-
async with McpKit.session("aminer") as call:
|
|
755
|
-
r1 = await call("search_paper_by_title", {"title": "A"})
|
|
756
|
-
r2 = await call("get_papers_info", {"id": "1"})
|
|
757
|
-
```
|
|
758
|
-
|
|
759
|
-
| 方法 | 说明 |
|
|
760
|
-
|------|------|
|
|
761
|
-
| `list_tools(server=None) -> list[dict]` | 工具发现;`server=None` 用档案 `default_server` |
|
|
762
|
-
| `call_tool(name, arguments, *, server=None) -> McpToolResult` | 同步短连接调用(主路径) |
|
|
763
|
-
| `call_tool_async(name, arguments, *, server=None) -> McpToolResult` | 异步版;FastAPI 等已有事件循环的进程内必须用 |
|
|
764
|
-
| `session(server=None)` | `async with` 长连接复用,产出 `call(name, arguments)` 协程函数 |
|
|
765
|
-
| `call_tool_url(url, name, arguments, *, token=None, transport="streamable-http", timeout=None) -> McpToolResult` | 直连临时服务器,不经档案 |
|
|
766
|
-
|
|
767
|
-
| 类型 | 说明 |
|
|
768
|
-
|------|------|
|
|
769
|
-
| `McpToolResult(server, tool, elapsed_ms, data)` | 调用结果;`data` 为 JSON 解析后对象,非 JSON 文本降级为字符串 |
|
|
770
|
-
| `McpKitError(message, *, detail=None)` | 业务失败时 `detail` 为服务端原始响应;连接失败时为最后一次传输层错误 |
|
|
771
|
-
|
|
772
|
-
> 传输方式仅 `streamable-http`(默认)与 `sse`;档案配 `fallback_url` 时主端点传输层失败会自动回退(业务失败不回退)。
|
|
773
|
-
|
|
774
|
-
---
|
|
775
|
-
|
|
776
776
|
## kit.redis_kit —— Redis 工具
|
|
777
777
|
|
|
778
778
|
安装:`pip install "sdpy-kit[redis]"`
|
|
@@ -1008,42 +1008,12 @@ MarkerKit.shutdown() # 释放模型与推理服务(幂等)
|
|
|
1008
1008
|
> `mode` 缺省时不写入配置,交由 marker 按设备自动选择;首次使用会下载模型权重(默认走 `MARKER_HF_ENDPOINT` 镜像)。
|
|
1009
1009
|
> 非 NVIDIA 平台完整 VLM 能力(公式 / 扫描页 OCR)需 llama.cpp 的 `llama-server`,否则用 `disable_ocr=True` 跳过。
|
|
1010
1010
|
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
## kit.zvec_kit —— 本地向量库
|
|
1014
|
-
|
|
1015
|
-
安装:`pip install "sdpy-kit[zvec]"`
|
|
1016
|
-
|
|
1017
|
-
```python
|
|
1018
|
-
from kit.zvec_kit import ZvecKit
|
|
1019
|
-
|
|
1020
|
-
schema = ZvecKit.make_text_embedding_schema("docs", dim=768)
|
|
1021
|
-
ZvecKit.create_collection("docs", schema)
|
|
1022
|
-
ZvecKit.insert("docs", {"id": "d1", "vectors": {"embedding": [0.1] * 768}, "fields": {"year": 2024}})
|
|
1023
|
-
|
|
1024
|
-
results = ZvecKit.vector_query("docs", field="embedding", vector=[0.3] * 768, topk=10)
|
|
1025
|
-
ZvecKit.flush("docs")
|
|
1026
|
-
```
|
|
1027
|
-
|
|
1028
|
-
| 分组 | 方法 |
|
|
1029
|
-
|------|------|
|
|
1030
|
-
| 连接 | `connect() -> bool`、`close() -> None`、`is_connected() -> bool` |
|
|
1031
|
-
| Collection | `create_collection(name_or_path, schema) -> Collection`、`open_collection(name_or_path)`、`collection_exists(name_or_path) -> bool`、`list_collections() -> list[str]`、`destroy_collection(name_or_path) -> bool`、`get_schema(name_or_path)`、`get_stats(name_or_path) -> dict` |
|
|
1032
|
-
| 文档 CRUD | `insert(name_or_path, data) -> str`、`insert_multi(name_or_path, data_list) -> list[str]`、`upsert(name_or_path, data) -> str`、`update(name_or_path, data) -> str`、`fetch(name_or_path, ids, *, include_vector=True) -> dict`、`delete(name_or_path, ids) -> bool`、`delete_by_filter(name_or_path, filter_expr) -> bool`、`count(name_or_path) -> int`、`flush(name_or_path) -> None` |
|
|
1033
|
-
| 检索 / 维护 | `vector_query(name_or_path, *, field, vector, topk=10, filter_expr=None, include_vector=False) -> list[dict]`、`optimize(name_or_path) -> None` |
|
|
1034
|
-
| Schema | `make_text_embedding_schema(name, dim, metric=None, extra_fields=None) -> CollectionSchema` |
|
|
1035
|
-
|
|
1036
|
-
> 文档字典键:`id`(必需)、`vectors`(可选)、`fields`(可选);`filter_expr` 中相等用单等号 `=`。
|
|
1037
|
-
> 异常:`ZvecError`(独立于 `kit.db` 的 `DBError` 体系)。
|
|
1038
|
-
|
|
1039
|
-
---
|
|
1040
|
-
|
|
1041
|
-
## kit.wx_article_kit —— 微信公众号文章抓取存储
|
|
1011
|
+
## kit.crawl.wx_article_kit —— 微信公众号文章抓取存储
|
|
1042
1012
|
|
|
1043
1013
|
零第三方依赖(标准库 `urllib` + 内置 HTML→Markdown 转换器),**无需 extra**,按需 import:
|
|
1044
1014
|
|
|
1045
1015
|
```python
|
|
1046
|
-
from kit.wx_article_kit import WxArticleKit
|
|
1016
|
+
from kit.crawl.wx_article_kit import WxArticleKit
|
|
1047
1017
|
|
|
1048
1018
|
# 抓取解析(不落盘)
|
|
1049
1019
|
result = WxArticleKit.fetch("https://mp.weixin.qq.com/s/xxxx")
|
|
@@ -1076,18 +1046,18 @@ WxArticleKit.save(url, "./output", "12345", write_meta=True)
|
|
|
1076
1046
|
`ArticleInfo.publish_time` 与 `meta.json` 内仍为 ISO 8601(结构化数据)。
|
|
1077
1047
|
- 无登录态抓取:命中微信风控(环境异常 / 访问过于频繁)时返回 `ok=False` + 原因,不破解验证码;
|
|
1078
1048
|
抓取或图片下载失败不抛异常,单张图片失败时正文保留原远程 URL。
|
|
1079
|
-
- 模型与 `WebArticleKit` 共用 `kit.article_models`(`ArticleInfo` 含 `source` / `site_host`);
|
|
1049
|
+
- 模型与 `WebArticleKit` 共用 `kit.crawl.article_models`(`ArticleInfo` 含 `source` / `site_host`);
|
|
1080
1050
|
失败时 `reason` 为类型化分类(微信常用 `risk_control` / `no_content` / `fetch_failed`)。
|
|
1081
1051
|
- 同名子目录**覆盖写**(不追加序号);`file_name` 带 `.md` 后缀会自动去除,为空则抛 `ValueError`。
|
|
1082
1052
|
|
|
1083
1053
|
---
|
|
1084
1054
|
|
|
1085
|
-
## kit.web_article_kit —— 通用网页文章抓取存储
|
|
1055
|
+
## kit.crawl.web_article_kit —— 通用网页文章抓取存储
|
|
1086
1056
|
|
|
1087
1057
|
可选依赖(`trafilatura`),需安装 `pip install "sdpy-kit[web-article]"`,按需 import:
|
|
1088
1058
|
|
|
1089
1059
|
```python
|
|
1090
|
-
from kit.web_article_kit import WebArticleKit
|
|
1060
|
+
from kit.crawl.web_article_kit import WebArticleKit
|
|
1091
1061
|
|
|
1092
1062
|
# 抓取解析(不落盘)
|
|
1093
1063
|
result = WebArticleKit.fetch("https://blog.csdn.net/xxx/article/details/123")
|
|
@@ -1116,12 +1086,12 @@ WebArticleKit.save(url, "./output", "12345", write_meta=True)
|
|
|
1116
1086
|
|---|---|
|
|
1117
1087
|
| 通用静态 / 服务端渲染页面(博客、文档站、CSDN 等) | ✅ 直接抽取 |
|
|
1118
1088
|
| 头条(文章页为 JS 空壳) | ✅ **明确支持**:走移动端 JSON 接口 |
|
|
1119
|
-
| 微信公众号 | ❌ **不覆盖**:返回提示,请改用 `kit.wx_article_kit.WxArticleKit`(该来源有专属解析,二者各自独立) |
|
|
1089
|
+
| 微信公众号 | ❌ **不覆盖**:返回提示,请改用 `kit.crawl.wx_article_kit.WxArticleKit`(该来源有专属解析,二者各自独立) |
|
|
1120
1090
|
| 正文依赖 JavaScript 动态渲染或需登录态的站点 | ❌ 失败并给出**类型化说明**(不维护域名名单) |
|
|
1121
1091
|
|
|
1122
1092
|
`ArticleInfo` 为平台中立的通用字段集:`url` / `title` / `author` / `publish_time`(ISO 8601)/ `source`
|
|
1123
1093
|
(来源平台名)/ `site_host` / `summary` / `images` / `links` / `code_blocks`,便于多平台抓取后写入同一张表;
|
|
1124
|
-
`to_dict()` 可直接 JSON 化(即 `meta.json` 的内容)。模型定义在 `kit.article_models`,与
|
|
1094
|
+
`to_dict()` 可直接 JSON 化(即 `meta.json` 的内容)。模型定义在 `kit.crawl.article_models`,与
|
|
1125
1095
|
`WxArticleKit` **共用同一套**。
|
|
1126
1096
|
|
|
1127
1097
|
质量信号(均不改变成功语义):
|
|
@@ -1135,15 +1105,13 @@ WebArticleKit.save(url, "./output", "12345", write_meta=True)
|
|
|
1135
1105
|
|
|
1136
1106
|
---
|
|
1137
1107
|
|
|
1138
|
-
## AI
|
|
1108
|
+
## AI 档案文件
|
|
1139
1109
|
|
|
1140
|
-
AI
|
|
1110
|
+
AI 功能需要在项目根目录提供 `config/ai_models.json`(chat / embedding / rerank / image 四类型多厂商模型档案)。
|
|
1141
1111
|
|
|
1142
|
-
- `config/ai_models.json` —— chat / embedding / rerank / image 四类型多厂商模型档案
|
|
1143
|
-
- `config/mcp_servers.json` —— MCP 服务器档案
|
|
1144
1112
|
|
|
1145
1113
|
文件缺失时,首次使用相应功能会报错,**报错信息中附带可直接复制的最小模板**;
|
|
1146
|
-
其中 `api_key`
|
|
1114
|
+
其中 `api_key` 字段填写环境变量名,真实密钥配置在 `.env`。
|
|
1147
1115
|
|
|
1148
1116
|
### ai_models.json 可选字段
|
|
1149
1117
|
|
|
@@ -1163,22 +1131,6 @@ AI 与 MCP 功能需要在项目根目录提供两个 JSON 档案文件:
|
|
|
1163
1131
|
全候选状态码一致时透传(如整链 429 可用 `exc.status_code == 429` 判定),
|
|
1164
1132
|
429 的 `Retry-After` 解析后挂于 `exc.retry_after`(冷却钳制 5–300s)。
|
|
1165
1133
|
|
|
1166
|
-
### mcp_servers.json 最小模板
|
|
1167
|
-
|
|
1168
|
-
```json
|
|
1169
|
-
{
|
|
1170
|
-
"default_server": "aminer",
|
|
1171
|
-
"servers": {
|
|
1172
|
-
"aminer": {
|
|
1173
|
-
"transport": "streamable-http",
|
|
1174
|
-
"url": "https://mcp.aminer.cn/mcp",
|
|
1175
|
-
"token_env": "AMINER_TOKEN",
|
|
1176
|
-
"timeout": 60
|
|
1177
|
-
}
|
|
1178
|
-
}
|
|
1179
|
-
}
|
|
1180
|
-
```
|
|
1181
|
-
|
|
1182
1134
|
## License
|
|
1183
1135
|
|
|
1184
1136
|
MIT
|