chatapi-translate


Namechatapi-translate JSON
Version 0.7 PyPI version JSON
download
home_pagehttps://github.com/aitsc/chatapi-translate
SummaryChatGPT OpenAI API 流式反向代理,自动翻译中文到英文对话,实现用英文进行高质量的对话
upload_time2023-05-28 09:20:03
maintainer
docs_urlNone
authoraitsc
requires_python>=3.7
licenseMIT
keywords tools
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # chatapi-translate
## 功能
- ChatGPT 通常英文对话效果比较好, 但是英文水平不行的话来回翻译比较麻烦, 这个项目通过包裹 OpenAI API 接口实现自动调用翻译器来翻译你的提问和助理的回答.
  - 英文靠谱例子:https://shareg.pt/jVBkjbD
  - 中文不靠谱例子(最后一次回答不对):https://shareg.pt/YfhCTDn
- 支持流式传输, 多轮对话自动提取英文上下文用于 ChatGPT.

![chatbox](images/example.png)
- 支持 百度翻译 / 腾讯翻译 / DeepL / 阿里翻译 / 彩云小译 / 火山翻译 / Google翻译 的API作为中转翻译器 (申请后都有免费额度)
- 支持直接使用 ChatGPT 翻译, 不过它经常回答问题而不是翻译问题[很难控制](images/chatgpt-trans.png), 大家要能找到好的prompt可以分享一下 (见配置示例)
  - 如果肯用 gpt-4 做翻译器, 翻译效果应该还是挺好的
- 不想使用翻译的时候可以输入 "--不翻译\n" (见配置文件)
- 支持 MacOS / Windows / Linux 全平台
- 因为会先输出英文回答, 还可以顺便学学英语~

## 搭建方法
### 1. 本地运行
- 安装 `python 3`
- 安装包 `pip3 install --upgrade chatapi-translate`
- 下载配置文件 [config_example.jsonc](https://github.com/aitsc/chatapi-translate/blob/master/config_example.jsonc) 并重命名为 `config.jsonc`
- 将 `config.jsonc` 中的翻译器密钥更换为你的([申请方法](https://bobtranslate.com/service/)), 其他参数可以看注释修改
- 配置文件同目录下运行: `chatapi-translate --port 7100`
- 现在你可以用 `http://127.0.0.1:7100` 替换 `https://api.openai.com` 的API域名在本地进行使用了, 例如你可以使用客户端 [chatbox](https://github.com/Bin-Huang/chatbox/releases)

### 2. 命令行测试
```shell
export CHATGLM_API_KEY=token1   # 你的 API key
curl http://127.0.0.1:7100/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $CHATGLM_API_KEY" \
  -d '{
    "model": "gpt-3.5-turbo",
    "messages": [{"role": "user", "content": "你是谁?"}]
  }'
```

### 3. 反向代理
```nginx
# vi /usr/local/nginx/conf/nginx.conf
http {
    server {
        listen 443 ssl;
        server_name 你的域名;
        ssl_certificate 你的证书路径.pem;
        ssl_certificate_key 你的密钥路径.key;
        location / {
            proxy_pass http://127.0.0.1:7100/;
            proxy_buffering off;
        }
    }
}
# /usr/local/nginx/sbin/nginx -s reload
```
配置好就可以在其他第三方客户端上修改 自定义API域名 为自己的域名进行使用了~

## 免搭建体验
借助 [ChatGPT Next Web](https://github.com/Yidadaa/ChatGPT-Next-Web) 项目自建了一个自动翻译对话的演示站点

有需要的话可直接进行体验: https://chatapi-translate.vercel.app

![chatgpt-next](images/chatgpt-next.png)

可以自动统计每次对话的token数量和官方API价格, 因为用了英文也更节省token~

(使用免费的翻译接口, 可能并发数量和额度有限制, 不建议大量使用)

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/aitsc/chatapi-translate",
    "name": "chatapi-translate",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "",
    "keywords": "tools",
    "author": "aitsc",
    "author_email": "",
    "download_url": "https://files.pythonhosted.org/packages/b9/a6/c1777bf6f0b88bd715dad829fac44bb615227a1637ecc6cf90b5baff5668/chatapi-translate-0.7.tar.gz",
    "platform": null,
    "description": "# chatapi-translate\n## \u529f\u80fd\n- ChatGPT \u901a\u5e38\u82f1\u6587\u5bf9\u8bdd\u6548\u679c\u6bd4\u8f83\u597d, \u4f46\u662f\u82f1\u6587\u6c34\u5e73\u4e0d\u884c\u7684\u8bdd\u6765\u56de\u7ffb\u8bd1\u6bd4\u8f83\u9ebb\u70e6, \u8fd9\u4e2a\u9879\u76ee\u901a\u8fc7\u5305\u88f9 OpenAI API \u63a5\u53e3\u5b9e\u73b0\u81ea\u52a8\u8c03\u7528\u7ffb\u8bd1\u5668\u6765\u7ffb\u8bd1\u4f60\u7684\u63d0\u95ee\u548c\u52a9\u7406\u7684\u56de\u7b54.\n  - \u82f1\u6587\u9760\u8c31\u4f8b\u5b50\uff1ahttps://shareg.pt/jVBkjbD\n  - \u4e2d\u6587\u4e0d\u9760\u8c31\u4f8b\u5b50(\u6700\u540e\u4e00\u6b21\u56de\u7b54\u4e0d\u5bf9)\uff1ahttps://shareg.pt/YfhCTDn\n- \u652f\u6301\u6d41\u5f0f\u4f20\u8f93, \u591a\u8f6e\u5bf9\u8bdd\u81ea\u52a8\u63d0\u53d6\u82f1\u6587\u4e0a\u4e0b\u6587\u7528\u4e8e ChatGPT.\n\n![chatbox](images/example.png)\n- \u652f\u6301 \u767e\u5ea6\u7ffb\u8bd1 / \u817e\u8baf\u7ffb\u8bd1 / DeepL / \u963f\u91cc\u7ffb\u8bd1 / \u5f69\u4e91\u5c0f\u8bd1 / \u706b\u5c71\u7ffb\u8bd1 / Google\u7ffb\u8bd1 \u7684API\u4f5c\u4e3a\u4e2d\u8f6c\u7ffb\u8bd1\u5668 (\u7533\u8bf7\u540e\u90fd\u6709\u514d\u8d39\u989d\u5ea6)\n- \u652f\u6301\u76f4\u63a5\u4f7f\u7528 ChatGPT \u7ffb\u8bd1, \u4e0d\u8fc7\u5b83\u7ecf\u5e38\u56de\u7b54\u95ee\u9898\u800c\u4e0d\u662f\u7ffb\u8bd1\u95ee\u9898[\u5f88\u96be\u63a7\u5236](images/chatgpt-trans.png), \u5927\u5bb6\u8981\u80fd\u627e\u5230\u597d\u7684prompt\u53ef\u4ee5\u5206\u4eab\u4e00\u4e0b (\u89c1\u914d\u7f6e\u793a\u4f8b)\n  - \u5982\u679c\u80af\u7528 gpt-4 \u505a\u7ffb\u8bd1\u5668, \u7ffb\u8bd1\u6548\u679c\u5e94\u8be5\u8fd8\u662f\u633a\u597d\u7684\n- \u4e0d\u60f3\u4f7f\u7528\u7ffb\u8bd1\u7684\u65f6\u5019\u53ef\u4ee5\u8f93\u5165 \"--\u4e0d\u7ffb\u8bd1\\n\" (\u89c1\u914d\u7f6e\u6587\u4ef6)\n- \u652f\u6301 MacOS / Windows / Linux \u5168\u5e73\u53f0\n- \u56e0\u4e3a\u4f1a\u5148\u8f93\u51fa\u82f1\u6587\u56de\u7b54, \u8fd8\u53ef\u4ee5\u987a\u4fbf\u5b66\u5b66\u82f1\u8bed\uff5e\n\n## \u642d\u5efa\u65b9\u6cd5\n### 1. \u672c\u5730\u8fd0\u884c\n- \u5b89\u88c5 `python 3`\n- \u5b89\u88c5\u5305 `pip3 install --upgrade chatapi-translate`\n- \u4e0b\u8f7d\u914d\u7f6e\u6587\u4ef6 [config_example.jsonc](https://github.com/aitsc/chatapi-translate/blob/master/config_example.jsonc) \u5e76\u91cd\u547d\u540d\u4e3a `config.jsonc`\n- \u5c06 `config.jsonc` \u4e2d\u7684\u7ffb\u8bd1\u5668\u5bc6\u94a5\u66f4\u6362\u4e3a\u4f60\u7684([\u7533\u8bf7\u65b9\u6cd5](https://bobtranslate.com/service/)), \u5176\u4ed6\u53c2\u6570\u53ef\u4ee5\u770b\u6ce8\u91ca\u4fee\u6539\n- \u914d\u7f6e\u6587\u4ef6\u540c\u76ee\u5f55\u4e0b\u8fd0\u884c: `chatapi-translate --port 7100`\n- \u73b0\u5728\u4f60\u53ef\u4ee5\u7528 `http://127.0.0.1:7100` \u66ff\u6362 `https://api.openai.com` \u7684API\u57df\u540d\u5728\u672c\u5730\u8fdb\u884c\u4f7f\u7528\u4e86, \u4f8b\u5982\u4f60\u53ef\u4ee5\u4f7f\u7528\u5ba2\u6237\u7aef [chatbox](https://github.com/Bin-Huang/chatbox/releases)\n\n### 2. \u547d\u4ee4\u884c\u6d4b\u8bd5\n```shell\nexport CHATGLM_API_KEY=token1   # \u4f60\u7684 API key\ncurl http://127.0.0.1:7100/v1/chat/completions \\\n  -H \"Content-Type: application/json\" \\\n  -H \"Authorization: Bearer $CHATGLM_API_KEY\" \\\n  -d '{\n    \"model\": \"gpt-3.5-turbo\",\n    \"messages\": [{\"role\": \"user\", \"content\": \"\u4f60\u662f\u8c01?\"}]\n  }'\n```\n\n### 3. \u53cd\u5411\u4ee3\u7406\n```nginx\n# vi /usr/local/nginx/conf/nginx.conf\nhttp {\n    server {\n        listen 443 ssl;\n        server_name \u4f60\u7684\u57df\u540d;\n        ssl_certificate \u4f60\u7684\u8bc1\u4e66\u8def\u5f84.pem;\n        ssl_certificate_key \u4f60\u7684\u5bc6\u94a5\u8def\u5f84.key;\n        location / {\n            proxy_pass http://127.0.0.1:7100/;\n            proxy_buffering off;\n        }\n    }\n}\n# /usr/local/nginx/sbin/nginx -s reload\n```\n\u914d\u7f6e\u597d\u5c31\u53ef\u4ee5\u5728\u5176\u4ed6\u7b2c\u4e09\u65b9\u5ba2\u6237\u7aef\u4e0a\u4fee\u6539 \u81ea\u5b9a\u4e49API\u57df\u540d \u4e3a\u81ea\u5df1\u7684\u57df\u540d\u8fdb\u884c\u4f7f\u7528\u4e86\uff5e\n\n## \u514d\u642d\u5efa\u4f53\u9a8c\n\u501f\u52a9 [ChatGPT Next Web](https://github.com/Yidadaa/ChatGPT-Next-Web) \u9879\u76ee\u81ea\u5efa\u4e86\u4e00\u4e2a\u81ea\u52a8\u7ffb\u8bd1\u5bf9\u8bdd\u7684\u6f14\u793a\u7ad9\u70b9\n\n\u6709\u9700\u8981\u7684\u8bdd\u53ef\u76f4\u63a5\u8fdb\u884c\u4f53\u9a8c: https://chatapi-translate.vercel.app\n\n![chatgpt-next](images/chatgpt-next.png)\n\n\u53ef\u4ee5\u81ea\u52a8\u7edf\u8ba1\u6bcf\u6b21\u5bf9\u8bdd\u7684token\u6570\u91cf\u548c\u5b98\u65b9API\u4ef7\u683c, \u56e0\u4e3a\u7528\u4e86\u82f1\u6587\u4e5f\u66f4\u8282\u7701token\uff5e\n\n(\u4f7f\u7528\u514d\u8d39\u7684\u7ffb\u8bd1\u63a5\u53e3, \u53ef\u80fd\u5e76\u53d1\u6570\u91cf\u548c\u989d\u5ea6\u6709\u9650\u5236, \u4e0d\u5efa\u8bae\u5927\u91cf\u4f7f\u7528)\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "ChatGPT OpenAI API \u6d41\u5f0f\u53cd\u5411\u4ee3\u7406\uff0c\u81ea\u52a8\u7ffb\u8bd1\u4e2d\u6587\u5230\u82f1\u6587\u5bf9\u8bdd\uff0c\u5b9e\u73b0\u7528\u82f1\u6587\u8fdb\u884c\u9ad8\u8d28\u91cf\u7684\u5bf9\u8bdd",
    "version": "0.7",
    "project_urls": {
        "Homepage": "https://github.com/aitsc/chatapi-translate"
    },
    "split_keywords": [
        "tools"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b9a6c1777bf6f0b88bd715dad829fac44bb615227a1637ecc6cf90b5baff5668",
                "md5": "8e6997642aa0b616006893c62217a3a1",
                "sha256": "9466a560213e8a3f550d6dfc2b651064ae54603761be4c36084ca18a1d05fb12"
            },
            "downloads": -1,
            "filename": "chatapi-translate-0.7.tar.gz",
            "has_sig": false,
            "md5_digest": "8e6997642aa0b616006893c62217a3a1",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 16796,
            "upload_time": "2023-05-28T09:20:03",
            "upload_time_iso_8601": "2023-05-28T09:20:03.830381Z",
            "url": "https://files.pythonhosted.org/packages/b9/a6/c1777bf6f0b88bd715dad829fac44bb615227a1637ecc6cf90b5baff5668/chatapi-translate-0.7.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-05-28 09:20:03",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "aitsc",
    "github_project": "chatapi-translate",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "lcname": "chatapi-translate"
}
        
Elapsed time: 1.03670s