diff --git a/README.en.md b/README.en.md index db9044935d..5fd96ec22c 100644 --- a/README.en.md +++ b/README.en.md @@ -174,6 +174,8 @@ pnpm dev - `TIMEOUT_MS` timeout, in milliseconds, optional - `SOCKS_PROXY_HOST` optional, effective with SOCKS_PROXY_PORT - `SOCKS_PROXY_PORT` optional, effective with SOCKS_PROXY_HOST +- `SOCKS_PROXY_USERNAME` optional, effective with SOCKS_PROXY_PASSWORD +- `SOCKS_PROXY_PASSWORD` optional, effective with SOCKS_PROXY_USERNAME ![docker](./docs/docker.png) @@ -223,6 +225,10 @@ services: SOCKS_PROXY_HOST: xxxx # socks proxy port, optional, effective with SOCKS_PROXY_HOST SOCKS_PROXY_PORT: xxxx + # optional, effective with SOCKS_PROXY_PASSWORD + SOCKS_PROXY_USERNAME: xxxx + # optional, effective with SOCKS_PROXY_USERNAME + SOCKS_PROXY_PASSWORD: xxxx ``` The `OPENAI_API_BASE_URL` is optional and only used when setting the `OPENAI_API_KEY`. The `OPENAI_API_MODEL` is optional and only used when setting the `OPENAI_API_KEY`. @@ -245,6 +251,8 @@ The `OPENAI_API_MODEL` is optional and only used when setting the `OPENAI_API_KE | `API_REVERSE_PROXY` | Optional, only for `Web API` | Reverse proxy address for `Web API`. [Details](https://github.com/transitive-bullshit/chatgpt-api#reverse-proxy) | | `SOCKS_PROXY_HOST` | Optional, effective with `SOCKS_PROXY_PORT` | Socks proxy. | | `SOCKS_PROXY_PORT` | Optional, effective with `SOCKS_PROXY_HOST` | Socks proxy port. | +| `SOCKS_PROXY_USERNAME` | Optional, effective with `SOCKS_PROXY_PASSWORD` | Socks proxy username. | +| `SOCKS_PROXY_PASSWORD` | Optional, effective with `SOCKS_PROXY_USERNAME` | Socks proxy password. | > Note: Changing environment variables in Railway will cause re-deployment. diff --git a/README.md b/README.md index 47797786f7..ab2f9b36ae 100644 --- a/README.md +++ b/README.md @@ -178,6 +178,8 @@ pnpm dev - `TIMEOUT_MS` 超时,单位毫秒,可选 - `SOCKS_PROXY_HOST` 可选,和 SOCKS_PROXY_PORT 一起时生效 - `SOCKS_PROXY_PORT` 可选,和 SOCKS_PROXY_HOST 一起时生效 +- `SOCKS_PROXY_USERNAME` 可选,和 SOCKS_PROXY_PASSWORD 一起时生效 +- `SOCKS_PROXY_PASSWORD` 可选,和 SOCKS_PROXY_USERNAME 一起时生效 ![docker](./docs/docker.png) @@ -223,10 +225,14 @@ services: AUTH_SECRET_KEY: xxx # 超时,单位毫秒,可选 TIMEOUT_MS: 60000 - # Socks代理,可选,和 SOCKS_PROXY_PORT 一起时生效 + # Socks 代理,可选,和 SOCKS_PROXY_PORT 一起时生效 SOCKS_PROXY_HOST: xxxx - # Socks代理端口,可选,和 SOCKS_PROXY_HOST 一起时生效 + # Socks 代理端口,可选,和 SOCKS_PROXY_HOST 一起时生效 SOCKS_PROXY_PORT: xxxx + # Socks 代理用户名,可选,和 SOCKS_PROXY_PASSWORD 一起时生效 + SOCKS_PROXY_USERNAME: xxxx + # Socks 代理密码,可选,和 SOCKS_PROXY_USERNAME 一起时生效 + SOCKS_PROXY_PASSWORD: xxxx ``` - `OPENAI_API_BASE_URL` 可选,设置 `OPENAI_API_KEY` 时可用 - `OPENAI_API_MODEL` 可选,设置 `OPENAI_API_KEY` 时可用 @@ -246,8 +252,10 @@ services: | `OPENAI_API_BASE_URL` | 可选,`OpenAI API` 时可用 | `API`接口地址 | | `OPENAI_API_MODEL` | 可选,`OpenAI API` 时可用 | `API`模型 | | `API_REVERSE_PROXY` | 可选,`Web API` 时可用 | `Web API` 反向代理地址 [详情](https://github.com/transitive-bullshit/chatgpt-api#reverse-proxy) | -| `SOCKS_PROXY_HOST` | 可选,和 `SOCKS_PROXY_PORT` 一起时生效 | Socks代理 | -| `SOCKS_PROXY_PORT` | 可选,和 `SOCKS_PROXY_HOST` 一起时生效 | Socks代理端口 | +| `SOCKS_PROXY_HOST` | 可选,和 `SOCKS_PROXY_PORT` 一起时生效 | Socks 代理 | +| `SOCKS_PROXY_PORT` | 可选,和 `SOCKS_PROXY_HOST` 一起时生效 | Socks 代理端口 | +| `SOCKS_PROXY_USERNAME` | 可选,和 `SOCKS_PROXY_PASSWORD` 一起时生效 | Socks 代理用户名 | +| `SOCKS_PROXY_PASSWORD` | 可选,和 `SOCKS_PROXY_USERNAME` 一起时生效 | Socks 代理密码 | > 注意: `Railway` 修改环境变量会重新 `Deploy` diff --git a/docker-compose/docker-compose.yml b/docker-compose/docker-compose.yml index f6082eddb4..b7c689adb0 100644 --- a/docker-compose/docker-compose.yml +++ b/docker-compose/docker-compose.yml @@ -20,10 +20,14 @@ services: AUTH_SECRET_KEY: xxx # 超时,单位毫秒,可选 TIMEOUT_MS: 60000 - # Socks代理,可选,和 SOCKS_PROXY_PORT 一起时生效 + # Socks 代理,可选,和 SOCKS_PROXY_PORT 一起时生效 SOCKS_PROXY_HOST: xxxx - # Socks代理端口,可选,和 SOCKS_PROXY_HOST 一起时生效 + # Socks 代理端口,可选,和 SOCKS_PROXY_HOST 一起时生效 SOCKS_PROXY_PORT: xxxx + # Socks 代理用户名,可选,和 SOCKS_PROXY_PASSWORD 一起时生效 + SOCKS_PROXY_USERNAME: xxxx + # Socks 代理密码,可选,和 SOCKS_PROXY_USERNAME 一起时生效 + SOCKS_PROXY_PASSWORD: xxxx nginx: image: nginx:alpine ports: diff --git a/service/.env.example b/service/.env.example index 43fe3a616c..0f9e5025ec 100644 --- a/service/.env.example +++ b/service/.env.example @@ -24,3 +24,9 @@ SOCKS_PROXY_HOST= # Socks Proxy Port SOCKS_PROXY_PORT= + +# Socks Proxy Username +SOCKS_PROXY_USERNAME= + +# Socks Proxy Password +SOCKS_PROXY_PASSWORD= diff --git a/service/src/chatgpt/index.ts b/service/src/chatgpt/index.ts index 9ddebafd63..6505d7c585 100644 --- a/service/src/chatgpt/index.ts +++ b/service/src/chatgpt/index.ts @@ -49,6 +49,8 @@ let api: ChatGPTAPI | ChatGPTUnofficialProxyAPI const agent = new SocksProxyAgent({ hostname: process.env.SOCKS_PROXY_HOST, port: process.env.SOCKS_PROXY_PORT, + username: process.env.SOCKS_PROXY_USERNAME || null, + password: process.env.SOCKS_PROXY_PASSWORD || null, }) options.fetch = (url, options) => { return fetch(url, { agent, ...options }) @@ -68,6 +70,8 @@ let api: ChatGPTAPI | ChatGPTUnofficialProxyAPI const agent = new SocksProxyAgent({ hostname: process.env.SOCKS_PROXY_HOST, port: process.env.SOCKS_PROXY_PORT, + username: process.env.SOCKS_PROXY_USERNAME || null, + password: process.env.SOCKS_PROXY_PASSWORD || null, }) options.fetch = (url, options) => { return fetch(url, { agent, ...options })