mdtomd 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.
@@ -0,0 +1,10 @@
1
+ include README.md
2
+ include pyproject.toml
3
+ graft mdtomd
4
+ graft scripts
5
+ prune tests
6
+ prune vscode-extension
7
+ prune examples
8
+ exclude config.yaml
9
+ exclude env.example
10
+ exclude llm-prices.md
mdtomd-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,137 @@
1
+ Metadata-Version: 2.4
2
+ Name: mdtomd
3
+ Version: 0.1.0
4
+ Summary: Markdown/MDX translation CLI
5
+ Keywords: markdown,mdx,translation,llm
6
+ Classifier: Environment :: Console
7
+ Classifier: Intended Audience :: Developers
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: Programming Language :: Python :: 3 :: Only
10
+ Classifier: Programming Language :: Python :: 3.9
11
+ Classifier: Programming Language :: Python :: 3.10
12
+ Classifier: Programming Language :: Python :: 3.11
13
+ Classifier: Topic :: Text Processing :: Markup
14
+ Requires-Python: >=3.9
15
+ Description-Content-Type: text/markdown
16
+ Requires-Dist: openai<2,>=1.75
17
+ Requires-Dist: tiktoken<1,>=0.8
18
+
19
+ # mdtomd
20
+
21
+ 一个给自己用的 Markdown/MDX 翻译工具。
22
+
23
+ 默认会读取当前目录的 `config.yaml`,支持:
24
+
25
+ - 单文件翻译
26
+ - 目录批量翻译
27
+ - `.md` / `.markdown` / `.mdx`
28
+ - 翻译前 token 估算
29
+ - 翻译后显示输入 / 输出 token
30
+
31
+ **安装**
32
+
33
+ 发布版安装:
34
+
35
+ ```bash
36
+ python3 -m pip install mdtomd
37
+ ```
38
+
39
+ 本地开发安装:
40
+
41
+ ```bash
42
+ python3 -m pip install -e .
43
+ ```
44
+
45
+ **配置**
46
+
47
+ 直接改 `config.yaml` 即可。
48
+
49
+ 常见方式:
50
+
51
+ 1. 在 `providers.<provider>` 里写 `model/base_url/api_key/max_tokens`
52
+ 2. 在 `llm.provider` 里选默认 provider
53
+ 3. `translator.chunk_size` 留空时,会默认跟当前模型的 `max_tokens` 一致
54
+ 4. 临时覆盖时再用命令行参数或环境变量
55
+
56
+ 如果不想把 key 写进配置,可以用环境变量,例如:
57
+
58
+ ```bash
59
+ export DEEPSEEK_API_KEY="your-key"
60
+ ```
61
+
62
+ **用法**
63
+
64
+ 快捷命令,先 estimate 再 translate:
65
+
66
+ ```bash
67
+ mdtomd examples/doc1.md
68
+ mdtomd examples
69
+ ```
70
+
71
+ 单文件翻译:
72
+
73
+ ```bash
74
+ mdtomd translate -i examples/doc1.md
75
+ ```
76
+
77
+ 目录翻译:
78
+
79
+ ```bash
80
+ mdtomd translate -i examples
81
+ ```
82
+
83
+ 目录输入会自动递归处理,并默认把结果写回原目录,生成 `*_zh.md` / `*_zh.mdx`。
84
+
85
+ 如果想输出到别的目录:
86
+
87
+ ```bash
88
+ mdtomd translate -i examples --output-dir out
89
+ ```
90
+
91
+ 先看 token:
92
+
93
+ ```bash
94
+ mdtomd estimate -i examples/doc1.md
95
+ mdtomd estimate -i examples
96
+ ```
97
+
98
+ 查看 provider 和模型:
99
+
100
+ ```bash
101
+ mdtomd providers
102
+ mdtomd models
103
+ ```
104
+
105
+ **输出说明**
106
+
107
+ 单文件翻译完成后会额外打印:
108
+
109
+ - `原文 tokens`
110
+ - `请求输入 tokens`
111
+ - `回复输出 tokens`
112
+
113
+ 其中:
114
+
115
+ - `请求输入 tokens` 是按当前 prompt 和分块策略统计的输入 token
116
+ - `回复输出 tokens` 是模型接口实际返回的 completion token
117
+
118
+ **测试**
119
+
120
+ ```bash
121
+ python3 -m unittest discover -s tests -v
122
+ ```
123
+
124
+ **CLI 发布**
125
+
126
+ 构建并检查产物:
127
+
128
+ ```bash
129
+ ./scripts/build_cli.sh
130
+ ```
131
+
132
+ 上传到 PyPI:
133
+
134
+ ```bash
135
+ export TWINE_PASSWORD="pypi-***"
136
+ ./scripts/publish_cli.sh
137
+ ```
mdtomd-0.1.0/README.md ADDED
@@ -0,0 +1,119 @@
1
+ # mdtomd
2
+
3
+ 一个给自己用的 Markdown/MDX 翻译工具。
4
+
5
+ 默认会读取当前目录的 `config.yaml`,支持:
6
+
7
+ - 单文件翻译
8
+ - 目录批量翻译
9
+ - `.md` / `.markdown` / `.mdx`
10
+ - 翻译前 token 估算
11
+ - 翻译后显示输入 / 输出 token
12
+
13
+ **安装**
14
+
15
+ 发布版安装:
16
+
17
+ ```bash
18
+ python3 -m pip install mdtomd
19
+ ```
20
+
21
+ 本地开发安装:
22
+
23
+ ```bash
24
+ python3 -m pip install -e .
25
+ ```
26
+
27
+ **配置**
28
+
29
+ 直接改 `config.yaml` 即可。
30
+
31
+ 常见方式:
32
+
33
+ 1. 在 `providers.<provider>` 里写 `model/base_url/api_key/max_tokens`
34
+ 2. 在 `llm.provider` 里选默认 provider
35
+ 3. `translator.chunk_size` 留空时,会默认跟当前模型的 `max_tokens` 一致
36
+ 4. 临时覆盖时再用命令行参数或环境变量
37
+
38
+ 如果不想把 key 写进配置,可以用环境变量,例如:
39
+
40
+ ```bash
41
+ export DEEPSEEK_API_KEY="your-key"
42
+ ```
43
+
44
+ **用法**
45
+
46
+ 快捷命令,先 estimate 再 translate:
47
+
48
+ ```bash
49
+ mdtomd examples/doc1.md
50
+ mdtomd examples
51
+ ```
52
+
53
+ 单文件翻译:
54
+
55
+ ```bash
56
+ mdtomd translate -i examples/doc1.md
57
+ ```
58
+
59
+ 目录翻译:
60
+
61
+ ```bash
62
+ mdtomd translate -i examples
63
+ ```
64
+
65
+ 目录输入会自动递归处理,并默认把结果写回原目录,生成 `*_zh.md` / `*_zh.mdx`。
66
+
67
+ 如果想输出到别的目录:
68
+
69
+ ```bash
70
+ mdtomd translate -i examples --output-dir out
71
+ ```
72
+
73
+ 先看 token:
74
+
75
+ ```bash
76
+ mdtomd estimate -i examples/doc1.md
77
+ mdtomd estimate -i examples
78
+ ```
79
+
80
+ 查看 provider 和模型:
81
+
82
+ ```bash
83
+ mdtomd providers
84
+ mdtomd models
85
+ ```
86
+
87
+ **输出说明**
88
+
89
+ 单文件翻译完成后会额外打印:
90
+
91
+ - `原文 tokens`
92
+ - `请求输入 tokens`
93
+ - `回复输出 tokens`
94
+
95
+ 其中:
96
+
97
+ - `请求输入 tokens` 是按当前 prompt 和分块策略统计的输入 token
98
+ - `回复输出 tokens` 是模型接口实际返回的 completion token
99
+
100
+ **测试**
101
+
102
+ ```bash
103
+ python3 -m unittest discover -s tests -v
104
+ ```
105
+
106
+ **CLI 发布**
107
+
108
+ 构建并检查产物:
109
+
110
+ ```bash
111
+ ./scripts/build_cli.sh
112
+ ```
113
+
114
+ 上传到 PyPI:
115
+
116
+ ```bash
117
+ export TWINE_PASSWORD="pypi-***"
118
+ ./scripts/publish_cli.sh
119
+ ```
@@ -0,0 +1,36 @@
1
+ from .config import (
2
+ AppConfig,
3
+ DefaultsConfig,
4
+ DisplayConfig,
5
+ FeaturedModelConfig,
6
+ LLMConfig,
7
+ ProviderOverrideConfig,
8
+ TranslatorConfig,
9
+ load_config,
10
+ )
11
+ from .llm import create_llm_client, list_supported_providers, resolve_runtime_config
12
+ from .pricing import ModelPrice, estimate_cost, lookup_model_price
13
+ from .translator import BatchTokenEstimate, FileTokenEstimate, MarkdownTokenEstimate, MarkdownTranslator, TranslateFilesOptions
14
+
15
+ __all__ = [
16
+ "AppConfig",
17
+ "DefaultsConfig",
18
+ "DisplayConfig",
19
+ "FeaturedModelConfig",
20
+ "BatchTokenEstimate",
21
+ "FileTokenEstimate",
22
+ "LLMConfig",
23
+ "ModelPrice",
24
+ "MarkdownTokenEstimate",
25
+ "MarkdownTranslator",
26
+ "ProviderOverrideConfig",
27
+ "TranslateFilesOptions",
28
+ "TranslatorConfig",
29
+ "create_llm_client",
30
+ "estimate_cost",
31
+ "list_supported_providers",
32
+ "load_config",
33
+ "lookup_model_price",
34
+ "resolve_runtime_config",
35
+ ]
36
+
@@ -0,0 +1,5 @@
1
+ from .cli import main
2
+
3
+
4
+ if __name__ == "__main__":
5
+ raise SystemExit(main())