ima-python-sdk 0.1.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.
- ima_python_sdk-0.1.0/LICENSE +21 -0
- ima_python_sdk-0.1.0/PKG-INFO +93 -0
- ima_python_sdk-0.1.0/README.md +68 -0
- ima_python_sdk-0.1.0/ima_python_sdk.egg-info/PKG-INFO +93 -0
- ima_python_sdk-0.1.0/ima_python_sdk.egg-info/SOURCES.txt +17 -0
- ima_python_sdk-0.1.0/ima_python_sdk.egg-info/dependency_links.txt +1 -0
- ima_python_sdk-0.1.0/ima_python_sdk.egg-info/entry_points.txt +2 -0
- ima_python_sdk-0.1.0/ima_python_sdk.egg-info/top_level.txt +1 -0
- ima_python_sdk-0.1.0/ima_sdk/__init__.py +90 -0
- ima_python_sdk-0.1.0/ima_sdk/cli.py +447 -0
- ima_python_sdk-0.1.0/ima_sdk/client.py +268 -0
- ima_python_sdk-0.1.0/ima_sdk/cos_uploader.py +158 -0
- ima_python_sdk-0.1.0/ima_sdk/file_checker.py +226 -0
- ima_python_sdk-0.1.0/ima_sdk/knowledge_base.py +591 -0
- ima_python_sdk-0.1.0/ima_sdk/logger.py +89 -0
- ima_python_sdk-0.1.0/ima_sdk/notes.py +343 -0
- ima_python_sdk-0.1.0/ima_sdk/types.py +424 -0
- ima_python_sdk-0.1.0/pyproject.toml +36 -0
- ima_python_sdk-0.1.0/setup.cfg +4 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 elxy
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: ima-python-sdk
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: 非官方的 IMA OpenAPI Python SDK,提供知识库和笔记管理功能
|
|
5
|
+
Author: elxy
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/elxy/ima-python-sdk
|
|
8
|
+
Project-URL: Repository, https://github.com/elxy/ima-python-sdk
|
|
9
|
+
Project-URL: Issues, https://github.com/elxy/ima-python-sdk/issues
|
|
10
|
+
Keywords: ima,knowledge-base,notes,sdk
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
20
|
+
Classifier: Operating System :: OS Independent
|
|
21
|
+
Requires-Python: >=3.8
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
License-File: LICENSE
|
|
24
|
+
Dynamic: license-file
|
|
25
|
+
|
|
26
|
+
# ima-python-sdk
|
|
27
|
+
|
|
28
|
+
非官方的 IMA OpenAPI Python SDK,提供知识库和笔记管理功能。
|
|
29
|
+
|
|
30
|
+
> 本项目参考 [ima-skills](https://clawhub.ai/iampennyli/ima-skills) 中的 API 文档和脚本实现,与 IMA 官方无关。
|
|
31
|
+
|
|
32
|
+
## 安装
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
pip install ima-python-sdk
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## 配置
|
|
39
|
+
|
|
40
|
+
SDK 需要 `client_id` 和 `api_key` 两个凭证,按以下优先级自动发现:
|
|
41
|
+
|
|
42
|
+
1. **构造参数** — `ImaClient(client_id="...", api_key="...")`
|
|
43
|
+
2. **环境变量** — `IMA_OPENAPI_CLIENTID` / `IMA_OPENAPI_APIKEY`
|
|
44
|
+
3. **配置文件** — `~/.config/ima/client_id` / `~/.config/ima/api_key`
|
|
45
|
+
|
|
46
|
+
## CLI 使用
|
|
47
|
+
|
|
48
|
+
`--kb_id` 可通过环境变量 `IMA_KB_ID` 设置,避免每次手动指定。
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
# 知识库
|
|
52
|
+
ima-sdk kb addable
|
|
53
|
+
ima-sdk kb upload report.pdf --kb_id xxx # 上传到根目录
|
|
54
|
+
ima-sdk kb upload report.pdf 论文/机器学习 --kb_id xxx # 上传到指定目录
|
|
55
|
+
ima-sdk kb import-url https://example.com --kb_id xxx
|
|
56
|
+
|
|
57
|
+
# 笔记
|
|
58
|
+
ima-sdk note search "会议记录"
|
|
59
|
+
ima-sdk note create "# 标题"
|
|
60
|
+
ima-sdk note read <doc_id> --raw
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## SDK 使用
|
|
64
|
+
|
|
65
|
+
```python
|
|
66
|
+
from ima_sdk import ImaClient, KnowledgeBaseManager, NotesManager
|
|
67
|
+
|
|
68
|
+
client = ImaClient() # 自动读取环境变量或配置文件
|
|
69
|
+
kb = KnowledgeBaseManager(client)
|
|
70
|
+
notes = NotesManager(client)
|
|
71
|
+
|
|
72
|
+
# 知识库操作
|
|
73
|
+
kb.upload_file("/path/to/report.pdf", knowledge_base_id="xxx")
|
|
74
|
+
kb.import_urls(["https://example.com"], knowledge_base_id="xxx")
|
|
75
|
+
results = kb.search_knowledge("关键词", knowledge_base_id="xxx")
|
|
76
|
+
|
|
77
|
+
# 笔记操作
|
|
78
|
+
doc_id = notes.create("# 标题\n\n正文内容")
|
|
79
|
+
docs, total, is_end = notes.search("会议记录")
|
|
80
|
+
content = notes.get_content(doc_id)
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## 特性
|
|
84
|
+
|
|
85
|
+
- **零第三方依赖** — 仅使用 Python 标准库(urllib, hmac, hashlib, dataclasses)
|
|
86
|
+
- **凭证自动发现** — 构造参数 > 环境变量 > 配置文件,三级优先
|
|
87
|
+
- **自动翻页** — 列表接口支持 `fetch_all=True`
|
|
88
|
+
- **完整上传流程** — `upload_file()` 一个方法完成预检、重名检查、创建媒体、COS 上传、添加知识
|
|
89
|
+
- **UTF-8 安全** — 笔记写入前自动校验编码
|
|
90
|
+
|
|
91
|
+
## License
|
|
92
|
+
|
|
93
|
+
MIT
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# ima-python-sdk
|
|
2
|
+
|
|
3
|
+
非官方的 IMA OpenAPI Python SDK,提供知识库和笔记管理功能。
|
|
4
|
+
|
|
5
|
+
> 本项目参考 [ima-skills](https://clawhub.ai/iampennyli/ima-skills) 中的 API 文档和脚本实现,与 IMA 官方无关。
|
|
6
|
+
|
|
7
|
+
## 安装
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pip install ima-python-sdk
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## 配置
|
|
14
|
+
|
|
15
|
+
SDK 需要 `client_id` 和 `api_key` 两个凭证,按以下优先级自动发现:
|
|
16
|
+
|
|
17
|
+
1. **构造参数** — `ImaClient(client_id="...", api_key="...")`
|
|
18
|
+
2. **环境变量** — `IMA_OPENAPI_CLIENTID` / `IMA_OPENAPI_APIKEY`
|
|
19
|
+
3. **配置文件** — `~/.config/ima/client_id` / `~/.config/ima/api_key`
|
|
20
|
+
|
|
21
|
+
## CLI 使用
|
|
22
|
+
|
|
23
|
+
`--kb_id` 可通过环境变量 `IMA_KB_ID` 设置,避免每次手动指定。
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
# 知识库
|
|
27
|
+
ima-sdk kb addable
|
|
28
|
+
ima-sdk kb upload report.pdf --kb_id xxx # 上传到根目录
|
|
29
|
+
ima-sdk kb upload report.pdf 论文/机器学习 --kb_id xxx # 上传到指定目录
|
|
30
|
+
ima-sdk kb import-url https://example.com --kb_id xxx
|
|
31
|
+
|
|
32
|
+
# 笔记
|
|
33
|
+
ima-sdk note search "会议记录"
|
|
34
|
+
ima-sdk note create "# 标题"
|
|
35
|
+
ima-sdk note read <doc_id> --raw
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## SDK 使用
|
|
39
|
+
|
|
40
|
+
```python
|
|
41
|
+
from ima_sdk import ImaClient, KnowledgeBaseManager, NotesManager
|
|
42
|
+
|
|
43
|
+
client = ImaClient() # 自动读取环境变量或配置文件
|
|
44
|
+
kb = KnowledgeBaseManager(client)
|
|
45
|
+
notes = NotesManager(client)
|
|
46
|
+
|
|
47
|
+
# 知识库操作
|
|
48
|
+
kb.upload_file("/path/to/report.pdf", knowledge_base_id="xxx")
|
|
49
|
+
kb.import_urls(["https://example.com"], knowledge_base_id="xxx")
|
|
50
|
+
results = kb.search_knowledge("关键词", knowledge_base_id="xxx")
|
|
51
|
+
|
|
52
|
+
# 笔记操作
|
|
53
|
+
doc_id = notes.create("# 标题\n\n正文内容")
|
|
54
|
+
docs, total, is_end = notes.search("会议记录")
|
|
55
|
+
content = notes.get_content(doc_id)
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## 特性
|
|
59
|
+
|
|
60
|
+
- **零第三方依赖** — 仅使用 Python 标准库(urllib, hmac, hashlib, dataclasses)
|
|
61
|
+
- **凭证自动发现** — 构造参数 > 环境变量 > 配置文件,三级优先
|
|
62
|
+
- **自动翻页** — 列表接口支持 `fetch_all=True`
|
|
63
|
+
- **完整上传流程** — `upload_file()` 一个方法完成预检、重名检查、创建媒体、COS 上传、添加知识
|
|
64
|
+
- **UTF-8 安全** — 笔记写入前自动校验编码
|
|
65
|
+
|
|
66
|
+
## License
|
|
67
|
+
|
|
68
|
+
MIT
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: ima-python-sdk
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: 非官方的 IMA OpenAPI Python SDK,提供知识库和笔记管理功能
|
|
5
|
+
Author: elxy
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/elxy/ima-python-sdk
|
|
8
|
+
Project-URL: Repository, https://github.com/elxy/ima-python-sdk
|
|
9
|
+
Project-URL: Issues, https://github.com/elxy/ima-python-sdk/issues
|
|
10
|
+
Keywords: ima,knowledge-base,notes,sdk
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
20
|
+
Classifier: Operating System :: OS Independent
|
|
21
|
+
Requires-Python: >=3.8
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
License-File: LICENSE
|
|
24
|
+
Dynamic: license-file
|
|
25
|
+
|
|
26
|
+
# ima-python-sdk
|
|
27
|
+
|
|
28
|
+
非官方的 IMA OpenAPI Python SDK,提供知识库和笔记管理功能。
|
|
29
|
+
|
|
30
|
+
> 本项目参考 [ima-skills](https://clawhub.ai/iampennyli/ima-skills) 中的 API 文档和脚本实现,与 IMA 官方无关。
|
|
31
|
+
|
|
32
|
+
## 安装
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
pip install ima-python-sdk
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## 配置
|
|
39
|
+
|
|
40
|
+
SDK 需要 `client_id` 和 `api_key` 两个凭证,按以下优先级自动发现:
|
|
41
|
+
|
|
42
|
+
1. **构造参数** — `ImaClient(client_id="...", api_key="...")`
|
|
43
|
+
2. **环境变量** — `IMA_OPENAPI_CLIENTID` / `IMA_OPENAPI_APIKEY`
|
|
44
|
+
3. **配置文件** — `~/.config/ima/client_id` / `~/.config/ima/api_key`
|
|
45
|
+
|
|
46
|
+
## CLI 使用
|
|
47
|
+
|
|
48
|
+
`--kb_id` 可通过环境变量 `IMA_KB_ID` 设置,避免每次手动指定。
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
# 知识库
|
|
52
|
+
ima-sdk kb addable
|
|
53
|
+
ima-sdk kb upload report.pdf --kb_id xxx # 上传到根目录
|
|
54
|
+
ima-sdk kb upload report.pdf 论文/机器学习 --kb_id xxx # 上传到指定目录
|
|
55
|
+
ima-sdk kb import-url https://example.com --kb_id xxx
|
|
56
|
+
|
|
57
|
+
# 笔记
|
|
58
|
+
ima-sdk note search "会议记录"
|
|
59
|
+
ima-sdk note create "# 标题"
|
|
60
|
+
ima-sdk note read <doc_id> --raw
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## SDK 使用
|
|
64
|
+
|
|
65
|
+
```python
|
|
66
|
+
from ima_sdk import ImaClient, KnowledgeBaseManager, NotesManager
|
|
67
|
+
|
|
68
|
+
client = ImaClient() # 自动读取环境变量或配置文件
|
|
69
|
+
kb = KnowledgeBaseManager(client)
|
|
70
|
+
notes = NotesManager(client)
|
|
71
|
+
|
|
72
|
+
# 知识库操作
|
|
73
|
+
kb.upload_file("/path/to/report.pdf", knowledge_base_id="xxx")
|
|
74
|
+
kb.import_urls(["https://example.com"], knowledge_base_id="xxx")
|
|
75
|
+
results = kb.search_knowledge("关键词", knowledge_base_id="xxx")
|
|
76
|
+
|
|
77
|
+
# 笔记操作
|
|
78
|
+
doc_id = notes.create("# 标题\n\n正文内容")
|
|
79
|
+
docs, total, is_end = notes.search("会议记录")
|
|
80
|
+
content = notes.get_content(doc_id)
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## 特性
|
|
84
|
+
|
|
85
|
+
- **零第三方依赖** — 仅使用 Python 标准库(urllib, hmac, hashlib, dataclasses)
|
|
86
|
+
- **凭证自动发现** — 构造参数 > 环境变量 > 配置文件,三级优先
|
|
87
|
+
- **自动翻页** — 列表接口支持 `fetch_all=True`
|
|
88
|
+
- **完整上传流程** — `upload_file()` 一个方法完成预检、重名检查、创建媒体、COS 上传、添加知识
|
|
89
|
+
- **UTF-8 安全** — 笔记写入前自动校验编码
|
|
90
|
+
|
|
91
|
+
## License
|
|
92
|
+
|
|
93
|
+
MIT
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
ima_python_sdk.egg-info/PKG-INFO
|
|
5
|
+
ima_python_sdk.egg-info/SOURCES.txt
|
|
6
|
+
ima_python_sdk.egg-info/dependency_links.txt
|
|
7
|
+
ima_python_sdk.egg-info/entry_points.txt
|
|
8
|
+
ima_python_sdk.egg-info/top_level.txt
|
|
9
|
+
ima_sdk/__init__.py
|
|
10
|
+
ima_sdk/cli.py
|
|
11
|
+
ima_sdk/client.py
|
|
12
|
+
ima_sdk/cos_uploader.py
|
|
13
|
+
ima_sdk/file_checker.py
|
|
14
|
+
ima_sdk/knowledge_base.py
|
|
15
|
+
ima_sdk/logger.py
|
|
16
|
+
ima_sdk/notes.py
|
|
17
|
+
ima_sdk/types.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
ima_sdk
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"""IMA Python SDK — 知识库和笔记操作。
|
|
2
|
+
|
|
3
|
+
用法::
|
|
4
|
+
|
|
5
|
+
from ima_sdk import ImaClient, KnowledgeBaseManager, NotesManager
|
|
6
|
+
|
|
7
|
+
client = ImaClient()
|
|
8
|
+
kb = KnowledgeBaseManager(client)
|
|
9
|
+
notes = NotesManager(client)
|
|
10
|
+
|
|
11
|
+
# 搜索知识库
|
|
12
|
+
results = kb.search_knowledge_base("我的资料")
|
|
13
|
+
|
|
14
|
+
# 上传文件到知识库
|
|
15
|
+
kb.upload_file("/path/to/report.pdf", knowledge_base_id="xxx")
|
|
16
|
+
|
|
17
|
+
# 创建笔记
|
|
18
|
+
doc_id = notes.create("# 标题\\n\\n正文内容")
|
|
19
|
+
|
|
20
|
+
# 搜索笔记
|
|
21
|
+
docs, total, is_end = notes.search("会议记录")
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
__version__ = "0.1.0"
|
|
25
|
+
|
|
26
|
+
from .client import ImaApiError, ImaClient
|
|
27
|
+
from .cos_uploader import cos_upload
|
|
28
|
+
from .file_checker import check_file
|
|
29
|
+
from .knowledge_base import KnowledgeBaseManager
|
|
30
|
+
from .notes import NotesManager
|
|
31
|
+
from .types import (
|
|
32
|
+
AddableKnowledgeBaseInfo,
|
|
33
|
+
CheckRepeatedNameResult,
|
|
34
|
+
ContentFormat,
|
|
35
|
+
CosCredential,
|
|
36
|
+
CreateMediaResult,
|
|
37
|
+
DocBasic,
|
|
38
|
+
FileCheckResult,
|
|
39
|
+
FileInfo,
|
|
40
|
+
FolderType,
|
|
41
|
+
ImportURLResult,
|
|
42
|
+
KBFolderInfo,
|
|
43
|
+
KnowledgeBaseInfo,
|
|
44
|
+
KnowledgeInfo,
|
|
45
|
+
KnowledgeListResult,
|
|
46
|
+
MediaType,
|
|
47
|
+
NoteBookInfo,
|
|
48
|
+
NoteFolderItem,
|
|
49
|
+
SearchedDoc,
|
|
50
|
+
SearchedKnowledgeBaseInfo,
|
|
51
|
+
SearchedKnowledgeInfo,
|
|
52
|
+
SearchType,
|
|
53
|
+
SortType,
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
__all__ = [
|
|
57
|
+
# 核心
|
|
58
|
+
"ImaClient",
|
|
59
|
+
"ImaApiError",
|
|
60
|
+
# 管理器
|
|
61
|
+
"KnowledgeBaseManager",
|
|
62
|
+
"NotesManager",
|
|
63
|
+
# 工具函数
|
|
64
|
+
"check_file",
|
|
65
|
+
"cos_upload",
|
|
66
|
+
# 类型
|
|
67
|
+
"KnowledgeBaseInfo",
|
|
68
|
+
"KnowledgeInfo",
|
|
69
|
+
"KBFolderInfo",
|
|
70
|
+
"AddableKnowledgeBaseInfo",
|
|
71
|
+
"SearchedKnowledgeBaseInfo",
|
|
72
|
+
"SearchedKnowledgeInfo",
|
|
73
|
+
"ImportURLResult",
|
|
74
|
+
"CosCredential",
|
|
75
|
+
"FileInfo",
|
|
76
|
+
"CreateMediaResult",
|
|
77
|
+
"CheckRepeatedNameResult",
|
|
78
|
+
"KnowledgeListResult",
|
|
79
|
+
"FileCheckResult",
|
|
80
|
+
"DocBasic",
|
|
81
|
+
"NoteFolderItem",
|
|
82
|
+
"NoteBookInfo",
|
|
83
|
+
"SearchedDoc",
|
|
84
|
+
# 枚举
|
|
85
|
+
"MediaType",
|
|
86
|
+
"ContentFormat",
|
|
87
|
+
"SearchType",
|
|
88
|
+
"SortType",
|
|
89
|
+
"FolderType",
|
|
90
|
+
]
|