Skip to main content

chatapi-translate

功能

  • ChatGPT 通常英文对话效果比较好, 但是英文水平不行的话来回翻译比较麻烦, 这个项目通过包裹 OpenAI API 接口实现自动调用翻译器来翻译你的提问和助理的回答.
  • 支持流式传输, 多轮对话自动提取英文上下文用于 ChatGPT.

chatbox

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

搭建方法

1. 本地运行

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

2. 命令行测试

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. 反向代理

# 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://chatapi-translate.vercel.app

chatgpt-next

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

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

Metadata

Release files for chatapi-translate 0.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for chatapi-translate 0.7
File Size Uploaded
chatapi-translate-0.7.tar.gz 16.8 kB Details

Release files / chatapi-translate-0.7.tar.gz

Download URL chatapi-translate-0.7.tar.gz
Size 16.8 kB
Tags Source
SHA-256 checksum
How to use checksums
9466a560213e8a3f550d6dfc2b651064ae54603761be4c36084ca18a1d05fb12
BLAKE2b-256 checksum
How to use checksums
b9a6c1777bf6f0b88bd715dad829fac44bb615227a1637ecc6cf90b5baff5668
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.13

Release history Release notifications | RSS feed

This release

0.7 This release

1 release file

0.6

1 release file

0.5

1 release file

0.4

1 release file

0.3

1 release file

0.2

1 release file

0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page