english-optimizer-cli 1.4.0 → 1.6.0
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.
- package/.claude/settings.local.json +12 -0
- package/.prettierrc.json +10 -0
- package/API_SETUP.md +2 -2
- package/LICENSE +21 -0
- package/README.md +13 -89
- package/README.zh-CN.md +458 -0
- package/SECURITY.md +53 -0
- package/dist/ai/api-provider.js +66 -70
- package/dist/ai/ollama.js +23 -45
- package/dist/config/config.js +0 -3
- package/dist/config/test.js +16 -1
- package/dist/core/instant-editor.js +1 -1
- package/dist/core/optimizer.js +13 -31
- package/dist/index.js +9 -8
- package/dist/prompts/templates.js +0 -4
- package/dist/prompts/translation-prompt.js +4 -6
- package/dist/utils/display.js +14 -16
- package/dist/utils/display.test.js +10 -0
- package/eslint.config.mjs +37 -0
- package/package.json +31 -19
package/.prettierrc.json
ADDED
package/API_SETUP.md
CHANGED
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 laosi
|
|
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.
|
package/README.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# English Optimizer CLI
|
|
2
2
|
|
|
3
|
+
[English](README.md) | [简体中文](README.zh-CN.md)
|
|
4
|
+
|
|
3
5
|
A powerful CLI tool to help non-native English speakers improve their writing using AI. Simply type your text and use hotkeys to instantly optimize it in different styles!
|
|
4
6
|
|
|
5
7
|
## Features
|
|
@@ -73,21 +75,13 @@ You can also customize the translation/optimization behavior using a text-based
|
|
|
73
75
|
### View Current Prompt
|
|
74
76
|
|
|
75
77
|
```bash
|
|
76
|
-
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
### Edit Prompt Template
|
|
80
|
-
|
|
81
|
-
```bash
|
|
82
|
-
fuck-abc prompt --edit
|
|
83
|
-
# Or edit directly
|
|
84
|
-
code ~/.english-optimizer/translation-prompt.txt
|
|
78
|
+
cao prompt --show
|
|
85
79
|
```
|
|
86
80
|
|
|
87
81
|
### Edit Prompt Template
|
|
88
82
|
|
|
89
83
|
```bash
|
|
90
|
-
|
|
84
|
+
cao prompt --edit
|
|
91
85
|
# Or edit directly
|
|
92
86
|
code ~/.english-optimizer/translation-prompt.txt
|
|
93
87
|
```
|
|
@@ -125,7 +119,6 @@ See `TRANSLATION_PROMPT_EXAMPLE.md` for more examples.
|
|
|
125
119
|
### 1. Clone and Install
|
|
126
120
|
|
|
127
121
|
```bash
|
|
128
|
-
cd /Users/laosi/Documents/repos/english-optimizer-cli
|
|
129
122
|
npm install
|
|
130
123
|
```
|
|
131
124
|
|
|
@@ -150,7 +143,7 @@ npm run build
|
|
|
150
143
|
```bash
|
|
151
144
|
npm start
|
|
152
145
|
# or
|
|
153
|
-
|
|
146
|
+
cao
|
|
154
147
|
```
|
|
155
148
|
|
|
156
149
|
## Usage
|
|
@@ -160,7 +153,7 @@ fuck-abc
|
|
|
160
153
|
Just run the CLI and start typing! Press **Cmd+key** to instantly optimize:
|
|
161
154
|
|
|
162
155
|
```bash
|
|
163
|
-
|
|
156
|
+
cao
|
|
164
157
|
# or
|
|
165
158
|
npm start
|
|
166
159
|
```
|
|
@@ -184,7 +177,7 @@ npm start
|
|
|
184
177
|
If you prefer to submit text first, then choose optimizations:
|
|
185
178
|
|
|
186
179
|
```bash
|
|
187
|
-
|
|
180
|
+
cao --classic
|
|
188
181
|
# or
|
|
189
182
|
npm start -- --classic
|
|
190
183
|
```
|
|
@@ -202,27 +195,27 @@ npm start -- --classic
|
|
|
202
195
|
### View History
|
|
203
196
|
|
|
204
197
|
```bash
|
|
205
|
-
|
|
206
|
-
|
|
198
|
+
cao history
|
|
199
|
+
cao history -n 5 # Show last 5 entries
|
|
207
200
|
```
|
|
208
201
|
|
|
209
202
|
### List Custom Prompts
|
|
210
203
|
|
|
211
204
|
```bash
|
|
212
|
-
|
|
205
|
+
cao prompts
|
|
213
206
|
```
|
|
214
207
|
|
|
215
208
|
### Check Configuration
|
|
216
209
|
|
|
217
210
|
```bash
|
|
218
211
|
# Show current configuration
|
|
219
|
-
|
|
212
|
+
cao config
|
|
220
213
|
|
|
221
214
|
# Run interactive setup wizard
|
|
222
|
-
|
|
215
|
+
cao config --setup
|
|
223
216
|
|
|
224
217
|
# Test API configuration
|
|
225
|
-
|
|
218
|
+
cao test
|
|
226
219
|
```
|
|
227
220
|
|
|
228
221
|
The test command will:
|
|
@@ -238,73 +231,6 @@ The setup wizard will guide you through:
|
|
|
238
231
|
- Configuring API settings
|
|
239
232
|
- Setting up preferences
|
|
240
233
|
|
|
241
|
-
### Using Cloud APIs (OpenAI, GLM, DeepSeek, etc.)
|
|
242
|
-
|
|
243
|
-
## YAML Prompt Configuration
|
|
244
|
-
|
|
245
|
-
The CLI supports YAML-based prompt configuration for more advanced customization.
|
|
246
|
-
|
|
247
|
-
### Using YAML Prompts
|
|
248
|
-
|
|
249
|
-
Create a `prompt.yaml` file in your project root (or any directory where you run the CLI):
|
|
250
|
-
|
|
251
|
-
```yaml
|
|
252
|
-
role:
|
|
253
|
-
name: Native English Full-Stack Engineer Coach
|
|
254
|
-
description: >
|
|
255
|
-
You are a senior full-stack software engineer who is a native English speaker.
|
|
256
|
-
You have strong experience in frontend, backend, system design, and real-world
|
|
257
|
-
engineering collaboration.
|
|
258
|
-
|
|
259
|
-
goals:
|
|
260
|
-
- Help the user learn natural, spoken English used by software engineers
|
|
261
|
-
- Translate the user's input into idiomatic, native-level English
|
|
262
|
-
- Optimize wording to sound natural, confident, and professional
|
|
263
|
-
|
|
264
|
-
user_profile:
|
|
265
|
-
background: Software Engineer
|
|
266
|
-
native_language: Chinese
|
|
267
|
-
learning_goal: Improve practical English for daily engineering communication
|
|
268
|
-
|
|
269
|
-
instructions:
|
|
270
|
-
- Always assume the user wants to improve their English, not just get a literal translation
|
|
271
|
-
- Rewrite the input in a way a native English-speaking engineer would naturally say it
|
|
272
|
-
- Prefer conversational, work-friendly language over academic or overly formal English
|
|
273
|
-
- Keep sentences concise and clear, like real team communication
|
|
274
|
-
|
|
275
|
-
output_format:
|
|
276
|
-
style: >
|
|
277
|
-
Natural, spoken English commonly used in engineering teams.
|
|
278
|
-
Sounds like real conversations in meetings, Slack, or code reviews.
|
|
279
|
-
|
|
280
|
-
examples:
|
|
281
|
-
- input: '这个需求我已经完成了,但是还需要再测试一下'
|
|
282
|
-
output: "I've finished this feature, but I still need to do some more testing."
|
|
283
|
-
|
|
284
|
-
- input: '这个问题我稍后再跟进'
|
|
285
|
-
output: "I'll follow up on this later."
|
|
286
|
-
|
|
287
|
-
constraints:
|
|
288
|
-
- Do not over-explain unless the user explicitly asks
|
|
289
|
-
- Do not change the original meaning
|
|
290
|
-
- Do not use overly complex vocabulary unless it fits real engineering conversations
|
|
291
|
-
```
|
|
292
|
-
|
|
293
|
-
### Managing YAML Prompts
|
|
294
|
-
|
|
295
|
-
```bash
|
|
296
|
-
# Check if YAML prompt is detected
|
|
297
|
-
fuck-abc prompt
|
|
298
|
-
|
|
299
|
-
# Show current YAML prompt configuration
|
|
300
|
-
fuck-abc prompt --show
|
|
301
|
-
|
|
302
|
-
# Edit YAML prompt file
|
|
303
|
-
fuck-abc prompt --edit
|
|
304
|
-
```
|
|
305
|
-
|
|
306
|
-
The CLI automatically detects `prompt.yaml` in the current directory and uses it for translation/optimization.
|
|
307
|
-
|
|
308
234
|
## Configuration
|
|
309
235
|
|
|
310
236
|
The CLI can be configured via:
|
|
@@ -336,8 +262,6 @@ API_MODEL=gpt-4o
|
|
|
336
262
|
|
|
337
263
|
For detailed API configuration instructions, see [API_SETUP.md](API_SETUP.md)
|
|
338
264
|
|
|
339
|
-
### Config File
|
|
340
|
-
|
|
341
265
|
### Environment Variables
|
|
342
266
|
|
|
343
267
|
Copy `.env.example` to `.env`:
|
package/README.zh-CN.md
ADDED
|
@@ -0,0 +1,458 @@
|
|
|
1
|
+
# English Optimizer CLI
|
|
2
|
+
|
|
3
|
+
[English](README.md) | [简体中文](README.zh-CN.md)
|
|
4
|
+
|
|
5
|
+
一个强大的 CLI 工具,帮助非英语母语者使用 AI 改进英文写作。只需输入文本并使用快捷键即可以不同风格即时优化!
|
|
6
|
+
|
|
7
|
+
## 功能特性
|
|
8
|
+
|
|
9
|
+
- 🎯 **交互模式** - 使用快捷键实时优化文本
|
|
10
|
+
- 🤖 **多种 AI 后端** - 支持本地 Ollama 或云端 API(OpenAI、GLM)
|
|
11
|
+
- 📝 **优化模式** - 专业、简洁、语法修正、资深开发者风格
|
|
12
|
+
- 📜 **历史记录** - 查看过往优化记录并学习
|
|
13
|
+
- 🔧 **自定义提示词** - 创建你自己的优化风格
|
|
14
|
+
- 🐋 **Docker 支持** - 使用 Docker 轻松设置 Ollama
|
|
15
|
+
- ⚡ **快速且私密** - 使用 Ollama 进行本地 AI 处理
|
|
16
|
+
|
|
17
|
+
## 前置要求
|
|
18
|
+
|
|
19
|
+
- Node.js 18+ 和 npm
|
|
20
|
+
- Docker(用于本地 Ollama 设置)
|
|
21
|
+
|
|
22
|
+
## YAML 提示词配置
|
|
23
|
+
|
|
24
|
+
你可以在项目根目录使用 YAML 文件配置 AI 行为:
|
|
25
|
+
|
|
26
|
+
### YAML 提示词文件
|
|
27
|
+
|
|
28
|
+
在项目根目录创建 `prompt.yaml` 文件:
|
|
29
|
+
|
|
30
|
+
```yaml
|
|
31
|
+
role:
|
|
32
|
+
name: Native English Full-Stack Engineer Coach
|
|
33
|
+
description: >
|
|
34
|
+
你是一位以英语为母语的资深全栈软件工程师。
|
|
35
|
+
你在前端、后端、系统设计和实际工程协作方面有丰富经验。
|
|
36
|
+
|
|
37
|
+
goals:
|
|
38
|
+
- 帮助用户学习软件工程师使用的自然、口语化英语
|
|
39
|
+
- 将用户的输入翻译成地道的、母语级别的英语
|
|
40
|
+
|
|
41
|
+
user_profile:
|
|
42
|
+
background: 软件工程师
|
|
43
|
+
native_language: 中文
|
|
44
|
+
learning_goal: 提高日常工程沟通的实用英语
|
|
45
|
+
|
|
46
|
+
instructions:
|
|
47
|
+
- 始终假设用户想要改进他们的英语
|
|
48
|
+
- 以英语母语工程师自然表达的方式重写输入
|
|
49
|
+
- 优先使用对话式、工作友好的语言,而不是学术或过于正式的英语
|
|
50
|
+
|
|
51
|
+
output_format:
|
|
52
|
+
style: >
|
|
53
|
+
工程团队中常用的自然、口语化英语。
|
|
54
|
+
听起来像会议、Slack 或代码审查中的真实对话。
|
|
55
|
+
|
|
56
|
+
examples:
|
|
57
|
+
- input: '这个需求我已经完成了,但是还需要再测试一下'
|
|
58
|
+
output: "I've finished this feature, but I still need to do some more testing."
|
|
59
|
+
|
|
60
|
+
- input: '这个问题我稍后再跟进'
|
|
61
|
+
output: "I'll follow up on this later."
|
|
62
|
+
|
|
63
|
+
constraints:
|
|
64
|
+
- 除非用户明确要求,否则不要过度解释
|
|
65
|
+
- 不要改变原意
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
CLI 将自动检测并使用当前目录中的 `prompt.yaml` 文件(如果存在)。
|
|
69
|
+
|
|
70
|
+
### 基于文本的提示词模板
|
|
71
|
+
|
|
72
|
+
你也可以使用基于文本的提示词自定义翻译/优化行为:
|
|
73
|
+
|
|
74
|
+
### 查看当前提示词
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
cao prompt --show
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### 编辑提示词模板
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
cao prompt --edit
|
|
84
|
+
# 或直接编辑
|
|
85
|
+
code ~/.english-optimizer/translation-prompt.txt
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### 自定义提示词示例
|
|
89
|
+
|
|
90
|
+
**正式商务英语:**
|
|
91
|
+
|
|
92
|
+
```
|
|
93
|
+
你是一位专业的商务翻译。
|
|
94
|
+
将文本翻译/优化为正式的商务英语,使用专业术语。
|
|
95
|
+
文本:"{text}"
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
**轻松的开发者聊天:**
|
|
99
|
+
|
|
100
|
+
```
|
|
101
|
+
你是一位软件开发者。
|
|
102
|
+
将文本翻译/优化为像 Slack 消息一样的轻松英语。
|
|
103
|
+
文本:"{text}"
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
**技术文档:**
|
|
107
|
+
|
|
108
|
+
```
|
|
109
|
+
你是一位技术文档翻译员。
|
|
110
|
+
将文本翻译/优化为精确的技术文档英语。
|
|
111
|
+
文本:"{text}"
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
查看 `TRANSLATION_PROMPT_EXAMPLE.md` 了解更多示例。
|
|
115
|
+
|
|
116
|
+
## 快速开始
|
|
117
|
+
|
|
118
|
+
### 1. 安装
|
|
119
|
+
|
|
120
|
+
```bash
|
|
121
|
+
npm install
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
### 2. 设置 Ollama(本地 AI)
|
|
125
|
+
|
|
126
|
+
```bash
|
|
127
|
+
# 使脚本可执行
|
|
128
|
+
chmod +x scripts/setup-ollama.sh
|
|
129
|
+
|
|
130
|
+
# 运行设置(启动 Ollama 并拉取模型)
|
|
131
|
+
./scripts/setup-ollama.sh
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
### 3. 构建 CLI
|
|
135
|
+
|
|
136
|
+
```bash
|
|
137
|
+
npm run build
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
### 4. 开始使用
|
|
141
|
+
|
|
142
|
+
```bash
|
|
143
|
+
npm start
|
|
144
|
+
# 或
|
|
145
|
+
cao
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
## 使用方法
|
|
149
|
+
|
|
150
|
+
### 即时模式(默认)
|
|
151
|
+
|
|
152
|
+
只需运行 CLI 并开始输入!按 **Cmd+键** 即时优化:
|
|
153
|
+
|
|
154
|
+
```bash
|
|
155
|
+
cao
|
|
156
|
+
# 或
|
|
157
|
+
npm start
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
**工作原理:**
|
|
161
|
+
|
|
162
|
+
1. 正常输入文本
|
|
163
|
+
2. 按 `Cmd+P` 切换到专业语气
|
|
164
|
+
3. 按 `Cmd+C` 切换到简洁版本
|
|
165
|
+
4. 按 `Cmd+G` 进行语法修正
|
|
166
|
+
5. 按 `Cmd+D` 切换到资深开发者风格
|
|
167
|
+
6. 按 **Enter** 接受优化,或继续输入以忽略
|
|
168
|
+
|
|
169
|
+
**控制:**
|
|
170
|
+
|
|
171
|
+
- `Ctrl+U` - 清除文本
|
|
172
|
+
- `Ctrl+C` - 退出
|
|
173
|
+
|
|
174
|
+
### 经典模式(可选)
|
|
175
|
+
|
|
176
|
+
如果你更喜欢先提交文本,然后选择优化:
|
|
177
|
+
|
|
178
|
+
```bash
|
|
179
|
+
cao --classic
|
|
180
|
+
# 或
|
|
181
|
+
npm start -- --classic
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
1. 输入文本(按两次 Enter 完成)
|
|
185
|
+
2. 按快捷键查看不同的优化:
|
|
186
|
+
- `Ctrl+P` - 专业语气
|
|
187
|
+
- `Ctrl+C` - 简洁版本
|
|
188
|
+
- `Ctrl+G` - 语法修正
|
|
189
|
+
- `Ctrl+D` - 资深开发者风格
|
|
190
|
+
- `Ctrl+R` - 重置为原始文本
|
|
191
|
+
- `Ctrl+H` - 查看历史
|
|
192
|
+
- `Ctrl+Q` - 退出
|
|
193
|
+
|
|
194
|
+
### 查看历史
|
|
195
|
+
|
|
196
|
+
```bash
|
|
197
|
+
cao history
|
|
198
|
+
cao history -n 5 # 显示最近 5 条记录
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
### 列出自定义提示词
|
|
202
|
+
|
|
203
|
+
```bash
|
|
204
|
+
cao prompts
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
### 检查配置
|
|
208
|
+
|
|
209
|
+
```bash
|
|
210
|
+
# 显示当前配置
|
|
211
|
+
cao config
|
|
212
|
+
|
|
213
|
+
# 运行交互式设置向导
|
|
214
|
+
cao config --setup
|
|
215
|
+
|
|
216
|
+
# 测试 API 配置
|
|
217
|
+
cao test
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
测试命令将:
|
|
221
|
+
|
|
222
|
+
- 验证你的 API 配置是否有效
|
|
223
|
+
- 测试与 API 提供商的连接
|
|
224
|
+
- 运行简单的优化测试
|
|
225
|
+
- 如果出现问题,显示详细的错误消息
|
|
226
|
+
|
|
227
|
+
设置向导将引导你完成:
|
|
228
|
+
|
|
229
|
+
- 选择 AI 提供商(本地 Ollama 或云端 API)
|
|
230
|
+
- 配置 API 设置
|
|
231
|
+
- 设置首选项
|
|
232
|
+
|
|
233
|
+
## 配置
|
|
234
|
+
|
|
235
|
+
CLI 可以通过以下方式配置:
|
|
236
|
+
|
|
237
|
+
1. **环境变量**(`.env` 文件)
|
|
238
|
+
2. **配置文件**(`~/.english-optimizer/config.yaml` 或 `~/.english-optimizer/config.json`)
|
|
239
|
+
|
|
240
|
+
### 使用云端 API(OpenAI、GLM、DeepSeek 等)
|
|
241
|
+
|
|
242
|
+
默认情况下,CLI 使用本地 Ollama。要使用云端 API,你需要配置它们。
|
|
243
|
+
|
|
244
|
+
**快速设置:**
|
|
245
|
+
|
|
246
|
+
1. 复制示例环境文件:
|
|
247
|
+
|
|
248
|
+
```bash
|
|
249
|
+
cp .env.example .env
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
2. 使用你的 API 配置编辑 `.env`:
|
|
253
|
+
|
|
254
|
+
```env
|
|
255
|
+
AI_PROVIDER=api
|
|
256
|
+
API_PROVIDER=openai # 或 'glm'、'custom'
|
|
257
|
+
API_KEY=your_api_key_here
|
|
258
|
+
API_BASE_URL=https://api.openai.com/v1
|
|
259
|
+
API_MODEL=gpt-4o
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
详细的 API 配置说明,请参见 [API_SETUP.md](API_SETUP.md)
|
|
263
|
+
|
|
264
|
+
### 环境变量
|
|
265
|
+
|
|
266
|
+
复制 `.env.example` 到 `.env`:
|
|
267
|
+
|
|
268
|
+
```bash
|
|
269
|
+
cp .env.example .env
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
编辑 `.env`:
|
|
273
|
+
|
|
274
|
+
```env
|
|
275
|
+
# AI 提供商:本地使用 'ollama',云端使用 'api'
|
|
276
|
+
AI_PROVIDER=ollama
|
|
277
|
+
|
|
278
|
+
# Ollama 配置(本地)
|
|
279
|
+
OLLAMA_BASE_URL=http://localhost:11434
|
|
280
|
+
OLLAMA_MODEL=llama3.2:3b
|
|
281
|
+
|
|
282
|
+
# API 配置(云端 - OpenAI/GLM)
|
|
283
|
+
# AI_PROVIDER=api
|
|
284
|
+
# API_PROVIDER=openai
|
|
285
|
+
# API_KEY=your_api_key_here
|
|
286
|
+
# API_BASE_URL=https://api.openai.com/v1
|
|
287
|
+
# API_MODEL=gpt-3.5-turbo
|
|
288
|
+
|
|
289
|
+
# GLM(智谱 AI)
|
|
290
|
+
# API_PROVIDER=glm
|
|
291
|
+
# API_KEY=your_glm_api_key
|
|
292
|
+
# API_BASE_URL=https://open.bigmodel.cn/api/paas/v4
|
|
293
|
+
# API_MODEL=glm-4
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
### 配置文件
|
|
297
|
+
|
|
298
|
+
配置文件可以是 YAML 或 JSON 格式,会自动创建在 `~/.english-optimizer/config.yaml`(或 `config.json`):
|
|
299
|
+
|
|
300
|
+
```yaml
|
|
301
|
+
ai:
|
|
302
|
+
provider: 'ollama'
|
|
303
|
+
ollama:
|
|
304
|
+
baseUrl: 'http://localhost:11434'
|
|
305
|
+
model: 'llama3.2:3b'
|
|
306
|
+
api:
|
|
307
|
+
provider: 'openai'
|
|
308
|
+
apiKey: ''
|
|
309
|
+
baseUrl: 'https://api.openai.com/v1'
|
|
310
|
+
model: 'gpt-3.5-turbo'
|
|
311
|
+
|
|
312
|
+
hotkeys:
|
|
313
|
+
professional: 'p'
|
|
314
|
+
concise: 'c'
|
|
315
|
+
grammar: 'g'
|
|
316
|
+
senior_developer: 'd'
|
|
317
|
+
reset: 'r'
|
|
318
|
+
history: 'h'
|
|
319
|
+
quit: 'q'
|
|
320
|
+
|
|
321
|
+
features:
|
|
322
|
+
enableHistory: true
|
|
323
|
+
historyPath: ~/.english-optimizer/history.json
|
|
324
|
+
enableCustomPrompts: true
|
|
325
|
+
customPromptsPath: ~/.english-optimizer/prompts.json
|
|
326
|
+
useYAMLPrompt: true
|
|
327
|
+
```
|
|
328
|
+
|
|
329
|
+
## 自定义提示词
|
|
330
|
+
|
|
331
|
+
你可以在 `~/.english-optimizer/prompts.json` 创建自定义优化提示词:
|
|
332
|
+
|
|
333
|
+
```json
|
|
334
|
+
[
|
|
335
|
+
{
|
|
336
|
+
"name": "Academic",
|
|
337
|
+
"description": "以适合研究论文的学术风格重写",
|
|
338
|
+
"prompt": "请以学术风格重写以下文本...",
|
|
339
|
+
"hotkey": "a"
|
|
340
|
+
},
|
|
341
|
+
{
|
|
342
|
+
"name": "Friendly",
|
|
343
|
+
"description": "使文本更加友好和随意",
|
|
344
|
+
"prompt": "请重写以下文本使其听起来更友好...",
|
|
345
|
+
"hotkey": "f"
|
|
346
|
+
}
|
|
347
|
+
]
|
|
348
|
+
```
|
|
349
|
+
|
|
350
|
+
## Docker 命令
|
|
351
|
+
|
|
352
|
+
```bash
|
|
353
|
+
# 启动 Ollama
|
|
354
|
+
docker-compose up -d
|
|
355
|
+
|
|
356
|
+
# 停止 Ollama
|
|
357
|
+
docker-compose down
|
|
358
|
+
|
|
359
|
+
# 查看日志
|
|
360
|
+
docker-compose logs -f ollama
|
|
361
|
+
|
|
362
|
+
# 重启 Ollama
|
|
363
|
+
docker-compose restart
|
|
364
|
+
```
|
|
365
|
+
|
|
366
|
+
## 生产部署
|
|
367
|
+
|
|
368
|
+
使用云端 API 而不是本地 Ollama:
|
|
369
|
+
|
|
370
|
+
1. 更新你的 `.env` 文件:
|
|
371
|
+
|
|
372
|
+
```env
|
|
373
|
+
AI_PROVIDER=api
|
|
374
|
+
API_PROVIDER=openai # 或 'glm' 用于智谱 AI
|
|
375
|
+
API_KEY=your_actual_api_key
|
|
376
|
+
API_MODEL=gpt-3.5-turbo # 或你喜欢的模型
|
|
377
|
+
```
|
|
378
|
+
|
|
379
|
+
2. CLI 将自动使用云端 API
|
|
380
|
+
|
|
381
|
+
## 开发
|
|
382
|
+
|
|
383
|
+
```bash
|
|
384
|
+
# 监视并重新构建
|
|
385
|
+
npm run watch
|
|
386
|
+
|
|
387
|
+
# 在开发模式下运行
|
|
388
|
+
npm run dev
|
|
389
|
+
|
|
390
|
+
# 代码检查
|
|
391
|
+
npm run lint
|
|
392
|
+
```
|
|
393
|
+
|
|
394
|
+
## 项目结构
|
|
395
|
+
|
|
396
|
+
```
|
|
397
|
+
english-optimizer-cli/
|
|
398
|
+
├── src/
|
|
399
|
+
│ ├── index.ts # CLI 入口点
|
|
400
|
+
│ ├── core/
|
|
401
|
+
│ │ ├── editor.ts # 带快捷键的交互式编辑器
|
|
402
|
+
│ │ └── optimizer.ts # 优化编排
|
|
403
|
+
│ ├── ai/
|
|
404
|
+
│ │ ├── provider.ts # AI 提供商工厂
|
|
405
|
+
│ │ ├── ollama.ts # Ollama 集成
|
|
406
|
+
│ │ └── api-provider.ts # OpenAI/GLM 集成
|
|
407
|
+
│ ├── prompts/
|
|
408
|
+
│ │ ├── templates.ts # 内置提示词模板
|
|
409
|
+
│ │ └── custom.ts # 自定义提示词加载器
|
|
410
|
+
│ ├── config/
|
|
411
|
+
│ │ └── config.ts # 配置管理
|
|
412
|
+
│ ├── history/
|
|
413
|
+
│ │ └── logger.ts # 历史记录
|
|
414
|
+
│ └── utils/
|
|
415
|
+
│ └── display.ts # 输出格式化
|
|
416
|
+
├── docker-compose.yml # Ollama Docker 设置
|
|
417
|
+
├── scripts/
|
|
418
|
+
│ └── setup-ollama.sh # 设置脚本
|
|
419
|
+
└── package.json
|
|
420
|
+
```
|
|
421
|
+
|
|
422
|
+
## 故障排除
|
|
423
|
+
|
|
424
|
+
### Ollama 连接失败
|
|
425
|
+
|
|
426
|
+
```bash
|
|
427
|
+
# 检查 Ollama 是否运行
|
|
428
|
+
docker-compose ps
|
|
429
|
+
|
|
430
|
+
# 重启 Ollama
|
|
431
|
+
docker-compose restart
|
|
432
|
+
|
|
433
|
+
# 检查 Ollama 日志
|
|
434
|
+
docker-compose logs ollama
|
|
435
|
+
```
|
|
436
|
+
|
|
437
|
+
### 未找到模型
|
|
438
|
+
|
|
439
|
+
```bash
|
|
440
|
+
# 手动拉取模型
|
|
441
|
+
docker exec -it english-optimizer-ollama ollama pull llama3.2:3b
|
|
442
|
+
```
|
|
443
|
+
|
|
444
|
+
### API 密钥问题
|
|
445
|
+
|
|
446
|
+
确保你的 `.env` 文件有正确的 API 密钥,且 API 提供商 URL 准确。
|
|
447
|
+
|
|
448
|
+
## 许可证
|
|
449
|
+
|
|
450
|
+
MIT
|
|
451
|
+
|
|
452
|
+
## 贡献
|
|
453
|
+
|
|
454
|
+
欢迎贡献!请随时提交 Pull Request。
|
|
455
|
+
|
|
456
|
+
## 作者
|
|
457
|
+
|
|
458
|
+
为世界各地的非英语母语者用 ❤️ 创建。
|