tketool.datasets 1.3.5__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.
- tketool_datasets-1.3.5/PKG-INFO +42 -0
- tketool_datasets-1.3.5/README.md +17 -0
- tketool_datasets-1.3.5/pyproject.toml +43 -0
- tketool_datasets-1.3.5/setup.cfg +4 -0
- tketool_datasets-1.3.5/src/tketool/datasets/__init__.py +19 -0
- tketool_datasets-1.3.5/src/tketool/datasets/cli.py +42 -0
- tketool_datasets-1.3.5/src/tketool/datasets/converts.py +82 -0
- tketool_datasets-1.3.5/src/tketool/datasets/dataset.py +1034 -0
- tketool_datasets-1.3.5/src/tketool/datasets/local.py +1377 -0
- tketool_datasets-1.3.5/src/tketool/datasets/memory.py +410 -0
- tketool_datasets-1.3.5/src/tketool/datasets/minio.py +547 -0
- tketool_datasets-1.3.5/src/tketool/datasets/operations.py +555 -0
- tketool_datasets-1.3.5/src/tketool/datasets/random.py +36 -0
- tketool_datasets-1.3.5/src/tketool/datasets/source.py +681 -0
- tketool_datasets-1.3.5/src/tketool/datasets/ssh.py +397 -0
- tketool_datasets-1.3.5/src/tketool.datasets.egg-info/PKG-INFO +42 -0
- tketool_datasets-1.3.5/src/tketool.datasets.egg-info/SOURCES.txt +19 -0
- tketool_datasets-1.3.5/src/tketool.datasets.egg-info/dependency_links.txt +1 -0
- tketool_datasets-1.3.5/src/tketool.datasets.egg-info/entry_points.txt +2 -0
- tketool_datasets-1.3.5/src/tketool.datasets.egg-info/requires.txt +11 -0
- tketool_datasets-1.3.5/src/tketool.datasets.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: tketool.datasets
|
|
3
|
+
Version: 1.3.5
|
|
4
|
+
Summary: Dataset contracts and local, memory, SSH, MinIO, and document adapters for tketool
|
|
5
|
+
Author-email: Ke <jiangke1207@icloud.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://pypi.org/project/tketool.datasets/
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
12
|
+
Classifier: Operating System :: OS Independent
|
|
13
|
+
Requires-Python: >=3.10
|
|
14
|
+
Description-Content-Type: text/markdown
|
|
15
|
+
Requires-Dist: tketool.core[console]==1.3.5
|
|
16
|
+
Requires-Dist: paramiko<6,>=4
|
|
17
|
+
Requires-Dist: minio<8,>=7.2.20
|
|
18
|
+
Requires-Dist: numpy<3,>=1.26
|
|
19
|
+
Requires-Dist: prettytable<4,>=3.12
|
|
20
|
+
Requires-Dist: pypdf<7,>=6
|
|
21
|
+
Requires-Dist: docx2txt<1,>=0.9
|
|
22
|
+
Requires-Dist: python-docx<2,>=1.2
|
|
23
|
+
Provides-Extra: test
|
|
24
|
+
Requires-Dist: pytest<9,>=8; extra == "test"
|
|
25
|
+
|
|
26
|
+
# tketool.datasets
|
|
27
|
+
|
|
28
|
+
Dataset and sample storage APIs for local files, memory, SSH/SFTP, MinIO,
|
|
29
|
+
PDF, Word, and random sampling workflows.
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
pip install tketool.datasets
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
```python
|
|
36
|
+
from tketool.datasets import Dataset, LocalDatasetSource
|
|
37
|
+
|
|
38
|
+
source = LocalDatasetSource("./data")
|
|
39
|
+
samples = Dataset(source, "train")
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
The retired `tketool.sample` and `tketool.mlsample` paths are not shipped.
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# tketool.datasets
|
|
2
|
+
|
|
3
|
+
Dataset and sample storage APIs for local files, memory, SSH/SFTP, MinIO,
|
|
4
|
+
PDF, Word, and random sampling workflows.
|
|
5
|
+
|
|
6
|
+
```bash
|
|
7
|
+
pip install tketool.datasets
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
```python
|
|
11
|
+
from tketool.datasets import Dataset, LocalDatasetSource
|
|
12
|
+
|
|
13
|
+
source = LocalDatasetSource("./data")
|
|
14
|
+
samples = Dataset(source, "train")
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
The retired `tketool.sample` and `tketool.mlsample` paths are not shipped.
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=77", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "tketool.datasets"
|
|
7
|
+
version = "1.3.5"
|
|
8
|
+
description = "Dataset contracts and local, memory, SSH, MinIO, and document adapters for tketool"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
authors = [{ name = "Ke", email = "jiangke1207@icloud.com" }]
|
|
13
|
+
dependencies = [
|
|
14
|
+
"tketool.core[console]==1.3.5",
|
|
15
|
+
"paramiko>=4,<6",
|
|
16
|
+
"minio>=7.2.20,<8",
|
|
17
|
+
"numpy>=1.26,<3",
|
|
18
|
+
"prettytable>=3.12,<4",
|
|
19
|
+
"pypdf>=6,<7",
|
|
20
|
+
"docx2txt>=0.9,<1",
|
|
21
|
+
"python-docx>=1.2,<2",
|
|
22
|
+
]
|
|
23
|
+
classifiers = [
|
|
24
|
+
"Programming Language :: Python :: 3",
|
|
25
|
+
"Programming Language :: Python :: 3.10",
|
|
26
|
+
"Programming Language :: Python :: 3.11",
|
|
27
|
+
"Programming Language :: Python :: 3.12",
|
|
28
|
+
"Operating System :: OS Independent",
|
|
29
|
+
]
|
|
30
|
+
|
|
31
|
+
[project.optional-dependencies]
|
|
32
|
+
test = ["pytest>=8,<9"]
|
|
33
|
+
|
|
34
|
+
[project.scripts]
|
|
35
|
+
tketool-datasets = "tketool.datasets.cli:main"
|
|
36
|
+
|
|
37
|
+
[project.urls]
|
|
38
|
+
Homepage = "https://pypi.org/project/tketool.datasets/"
|
|
39
|
+
|
|
40
|
+
[tool.setuptools.packages.find]
|
|
41
|
+
where = ["src"]
|
|
42
|
+
include = ["tketool*"]
|
|
43
|
+
namespaces = true
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"""Dataset contracts and local, memory, SSH, and MinIO adapters."""
|
|
2
|
+
|
|
3
|
+
from .dataset import Dataset
|
|
4
|
+
from .local import LocalDatasetSource
|
|
5
|
+
from .memory import MemoryDatasetSource
|
|
6
|
+
from .minio import MinioDatasetSource
|
|
7
|
+
from .random import create_dataset
|
|
8
|
+
from .source import DatasetSource
|
|
9
|
+
from .ssh import SshDatasetSource
|
|
10
|
+
|
|
11
|
+
__all__ = [
|
|
12
|
+
"Dataset",
|
|
13
|
+
"DatasetSource",
|
|
14
|
+
"LocalDatasetSource",
|
|
15
|
+
"MemoryDatasetSource",
|
|
16
|
+
"MinioDatasetSource",
|
|
17
|
+
"SshDatasetSource",
|
|
18
|
+
"create_dataset",
|
|
19
|
+
]
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# pass_generate pass_doc
|
|
2
|
+
import argparse
|
|
3
|
+
import inspect
|
|
4
|
+
from tketool.core.commands import add_command_parser
|
|
5
|
+
from tketool.datasets.operations import (
|
|
6
|
+
capture_str,
|
|
7
|
+
delete_set,
|
|
8
|
+
download,
|
|
9
|
+
find_s,
|
|
10
|
+
output_csv,
|
|
11
|
+
set_data_info,
|
|
12
|
+
set_info,
|
|
13
|
+
set_list,
|
|
14
|
+
upload,
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def main():
|
|
19
|
+
parser = argparse.ArgumentParser(description="A simple command line tool")
|
|
20
|
+
commands = {}
|
|
21
|
+
|
|
22
|
+
# Only create subparsers once
|
|
23
|
+
subparsers = parser.add_subparsers(dest="command", help='Commands')
|
|
24
|
+
|
|
25
|
+
add_command_parser(subparsers, set_list, commands) # Add your functions here
|
|
26
|
+
add_command_parser(subparsers, set_info, commands)
|
|
27
|
+
add_command_parser(subparsers, delete_set, commands)
|
|
28
|
+
add_command_parser(subparsers, set_data_info, commands)
|
|
29
|
+
add_command_parser(subparsers, capture_str, commands)
|
|
30
|
+
add_command_parser(subparsers, upload, commands)
|
|
31
|
+
add_command_parser(subparsers, find_s, commands)
|
|
32
|
+
add_command_parser(subparsers, download, commands)
|
|
33
|
+
add_command_parser(subparsers, output_csv, commands)
|
|
34
|
+
|
|
35
|
+
args = parser.parse_args()
|
|
36
|
+
|
|
37
|
+
if args.command in commands:
|
|
38
|
+
command_params = inspect.signature(commands[args.command]).parameters
|
|
39
|
+
params = {name: getattr(args, name, None) for name in command_params}
|
|
40
|
+
commands[args.command](**params)
|
|
41
|
+
else:
|
|
42
|
+
parser.print_help()
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
# pass_generate
|
|
2
|
+
from tketool.datasets.source import DatasetSource
|
|
3
|
+
from tketool.datasets.dataset import Dataset
|
|
4
|
+
import json
|
|
5
|
+
from tketool.core.files import write_file_lines
|
|
6
|
+
import docx2txt
|
|
7
|
+
import pypdf
|
|
8
|
+
from docx import Document
|
|
9
|
+
from zipfile import BadZipFile
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def convert_jsonl(datasource: DatasetSource, set_name: str, prompt_completion_fun,
|
|
14
|
+
target_path: str):
|
|
15
|
+
"""
|
|
16
|
+
这个函数用于将数据源中的数据转换为jsonl文件。函数首先会从数据源中读取指定的“set_name”的样本集,然后使用“prompt_completion_fun”函数将每个样本的问题和答案转换为字典形式,最后将所有的行写入到“target_path”指定的文件中。
|
|
17
|
+
|
|
18
|
+
参数:
|
|
19
|
+
datasource(DatasetSource): 数据源,必须是DatasetSource类型或其子类的实例。
|
|
20
|
+
set_name(str): 从数据源中获取样本集的名称。
|
|
21
|
+
prompt_completion_fun(function): 用于将样本转换为字典形式的函数。该函数必须接受一个参数(样本),并返回一个元组,元组的第一个元素是问题,第二个元素是答案。
|
|
22
|
+
target_path(str): 输出jsonl文件的路径。
|
|
23
|
+
|
|
24
|
+
返回:
|
|
25
|
+
None
|
|
26
|
+
|
|
27
|
+
示例:
|
|
28
|
+
|
|
29
|
+
def prompt_completion(item):
|
|
30
|
+
return item.question, item.answer
|
|
31
|
+
|
|
32
|
+
datasource = MyDataSource()
|
|
33
|
+
convert_jsonl(datasource, "train", prompt_completion, "train.jsonl")
|
|
34
|
+
|
|
35
|
+
注意:这个函数不会检查“target_path”是否已经存在,如果存在,它会直接覆盖旧文件。
|
|
36
|
+
|
|
37
|
+
错误与异常:
|
|
38
|
+
如果数据源中不存在指定的“set_name”,函数会抛出异常。
|
|
39
|
+
如果“prompt_completion_fun”函数不能正确处理样本,也会抛出异常。
|
|
40
|
+
"""
|
|
41
|
+
|
|
42
|
+
row_lines = []
|
|
43
|
+
for item in Dataset(datasource, set_name):
|
|
44
|
+
prompt, completion = prompt_completion_fun(item)
|
|
45
|
+
row_data = {
|
|
46
|
+
'prompt': prompt,
|
|
47
|
+
'completion': completion
|
|
48
|
+
}
|
|
49
|
+
row_str = json.dumps(row_data)
|
|
50
|
+
row_lines.append(row_str)
|
|
51
|
+
|
|
52
|
+
write_file_lines(target_path, row_lines)
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def doc_to_txt(file_path, txt_path):
|
|
56
|
+
try:
|
|
57
|
+
text = docx2txt.process(file_path)
|
|
58
|
+
except BadZipFile:
|
|
59
|
+
print(f'Failed to process {file_path}: not a .doc file or file is corrupted.')
|
|
60
|
+
text = ''
|
|
61
|
+
with open(txt_path, 'w') as output:
|
|
62
|
+
output.write(text)
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def docx_to_txt(file_path, txt_path):
|
|
66
|
+
try:
|
|
67
|
+
doc = Document(file_path)
|
|
68
|
+
text = '\n'.join([paragraph.text for paragraph in doc.paragraphs])
|
|
69
|
+
except BadZipFile:
|
|
70
|
+
print(f'Failed to process {file_path}: not a .docx file or file is corrupted.')
|
|
71
|
+
text = ''
|
|
72
|
+
with open(txt_path, 'w') as output:
|
|
73
|
+
output.write(text)
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def pdf_to_txt(file_path, txt_path):
|
|
77
|
+
with open(file_path, 'rb') as pdf_file_obj:
|
|
78
|
+
pdf_reader = pypdf.PdfReader(pdf_file_obj)
|
|
79
|
+
num_pages = len(pdf_reader.pages)
|
|
80
|
+
text = '\n'.join([page.extract_text() for page in pdf_reader.pages])
|
|
81
|
+
with open(txt_path, 'w') as output:
|
|
82
|
+
output.write(text)
|