# 命令行工具chatgpt-tr v0.0.2: 免费翻译，仅需access token（及提子（如需要））

**URL:** <https://forum.freemdict.com/t/topic/20546>\
**Category:** 软件经验交流展望\
**Tags:** 工具, chatgpt, 命令行\
**Created:** [2023 年4 月 15 日 05:51 UTC](https://forum.freemdict.com/t/topic/20546 "2023-04-15T05:51:04Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

作者： ![mikeee](https://forumcdn.freemdict.com/user_avatar/forum.freemdict.com/mikeee/32/18656_2.png) [@mikeee](https://forum.freemdict.com/u/mikeee)\
发布日期： [2023 年4 月 15 日 05:51 UTC](https://forum.freemdict.com/t/topic/20546/1 "2023-04-15T05:51:04Z")

</div>

[chatgpt-tr-v0.0.2.zip](https://forum.freemdict.com/uploads/short-url/oPgS9aM1GCGqC72sko4REiQx8oC.zip) (11.3 MB)

用法

- 解压 chatgpt-tr-v0.0.2.zip （v0.0.1版的反向代理失效）
- 获取access token
  - 登录 [chat.openai.com](http://chat.openai.com)
  - 访问 [https://chat.openai.com/api/auth/session](https://chat.openai.com/api/auth/session)
  - 拷 accessToken备用
  - 此操作只需一次。（access token 有效期约30天，但内地ip可能需双向提子因为openai和大火墙的双重封杀）

- 命令行下设置环境变量OPENAI\_ACCESS\_TOKEN，例如cmd下 `set OPENAI_ACCESS_TOKEN=eyJhbGc...` 或用包内的 chatgpt-tr.bat
- 命令行下，例如WIN cmd回车（或开`Windows Terminal`或`cmder`或`conemu`）
  - `chatgpt_tr --help` # 帮助
  - `chatgpr_tr` # 翻译系统剪贴板内容
  - `chatgpr_tr this is a test` # 翻译 this is a test

chatgpt\_tr 主要用于辅助难句或短语翻译，但也可以用于对话（运行 `chatgpt_tr --help` 查看详情。上下文关联部分未有详细测试）。  
反应有点慢，但用于翻译辅助可能也无关紧要（想象一下等待期间可以继续做其他翻译）。如有必要，会持续改进。

chatgpt\_tr 基于某个第三方反向代理，代理挂了或被关闭当然chatgpt\_tr 也就不能用了。

典型输出：

```bash
# chatgpt_tr amazon code whisperer
amazon code whisperer

版本1：
亚马逊代码耳语师

版本2：
亚马逊代码密语者

版本3：
亚马逊代码秘语师

# chatgpt_tr.exe -p "列出5个中文同义词" make sense
make sense

1. 有道理
2. 讲得通
3. 合理
4. 明智
5. 理性

# chatgpt_tr.exe --help

 Usage: chatgpt_tr.exe [OPTIONS] [TEXT]...

 Translate with chatgpt using access token.
 set LOGURU_LEVEL=DEBUG or set LOGLEVEL=10 to turn on debug/verbose mode.

┌─ Arguments ──────────────────────────────────────────────────────────────────┐
│ text [TEXT]... Source text. [default: None] │
└──────────────────────────────────────────────────────────────────────────────┘
┌─ Options ────────────────────────────────────────────────────────────────────┐
│ --version -v,-V Show version info and a list of supported │
│ languages and exit. │
│ --clipb -c Use clipboard content if set or if `text` is │
│ empty. │
│ --to-lang -t TEXT Target language when using the default │
│ prompt. │
│ [default: 中文] │
│ --numb -n INTEGER number of translation variants when using the │
│ default prompt. │
│ [default: 3] │
│ --prompt -p TEXT User defined prompt. [default: │
│ '将以下内容内容翻成 to_lang │
│ (中文)，不要自由发挥，列出 numb (3) 个版本： │
│ \n'] │
│ --help Show this message and exit.

```

如果你在用 GoldenDict 的话，也可以从GoldenDict调用。具体设置参看隔壁论坛相关帖。

有必要的话，我也可以提供 python 源码。核心码也就十几行。
