From d3daa654a7c612858868512ba05a54621dcbc5b7 Mon Sep 17 00:00:00 2001 From: xieccc Date: Thu, 9 Mar 2023 18:38:30 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9EAPI=E6=A8=A1=E5=9E=8B?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E9=A1=B9=20(#404)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * chore: 更新文档 * Improve zh-TW locale (#379) * fix: 移动端样式 * feat: typo * fix: 调整滚动回原样 * feat: 新增API模型配置项 --------- Co-authored-by: ChenZhaoYu <790348264@qq.com> Co-authored-by: Peter Dave Hello --- README.en.md | 5 +++++ README.md | 5 +++++ docker-compose/docker-compose.yml | 2 ++ service/.env | 3 +++ service/src/chatgpt/index.ts | 2 +- 5 files changed, 16 insertions(+), 1 deletion(-) diff --git a/README.en.md b/README.en.md index 6fa93e45dc..cba57cd321 100644 --- a/README.en.md +++ b/README.en.md @@ -168,6 +168,7 @@ pnpm dev - `OPENAI_API_KEY` one of two - `OPENAI_ACCESS_TOKEN` one of two, `OPENAI_API_KEY` takes precedence when both are present - `OPENAI_API_BASE_URL` optional, available when `OPENAI_API_KEY` is set +- `OPENAI_API_Model` optional, available when `OPENAI_API_KEY` is set - `API_REVERSE_PROXY` optional, available when `OPENAI_ACCESS_TOKEN` is set [Reference](#introduction) - `AUTH_SECRET_KEY` Access Password,optional - `TIMEOUT_MS` timeout, in milliseconds, optional @@ -210,6 +211,8 @@ services: OPENAI_ACCESS_TOKEN: xxxxxx # api interface url, optional, available when OPENAI_API_KEY is set OPENAI_API_BASE_URL: xxxx + # api model, optional, available when OPENAI_API_KEY is set + OPENAI_API_Model: xxxx # reverse proxy, optional API_REVERSE_PROXY: xxx # access password,optional @@ -222,6 +225,7 @@ services: SOCKS_PROXY_PORT: 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`. ### Deployment with Railway @@ -237,6 +241,7 @@ The `OPENAI_API_BASE_URL` is optional and only used when setting the `OPENAI_API | `OPENAI_API_KEY` | Optional | Required for `OpenAI API`. `apiKey` can be obtained from [here](https://platform.openai.com/overview). | | `OPENAI_ACCESS_TOKEN`| Optional | Required for `Web API`. `accessToken` can be obtained from [here](https://chat.openai.com/api/auth/session).| | `OPENAI_API_BASE_URL` | Optional, only for `OpenAI API` | API endpoint. | +| `OPENAI_API_Model` | Optional, only for `OpenAI API` | API model. | | `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. | diff --git a/README.md b/README.md index 4f421fb154..b38a741bdd 100644 --- a/README.md +++ b/README.md @@ -166,6 +166,7 @@ pnpm dev - `OPENAI_API_KEY` 二选一 - `OPENAI_ACCESS_TOKEN` 二选一,同时存在时,`OPENAI_API_KEY` 优先 - `OPENAI_API_BASE_URL` 可选,设置 `OPENAI_API_KEY` 时可用 +- `OPENAI_API_Model` 可选,设置 `OPENAI_API_KEY` 时可用 - `API_REVERSE_PROXY` 可选,设置 `OPENAI_ACCESS_TOKEN` 时可用 [参考](#介绍) - `AUTH_SECRET_KEY` 访问权限密钥,可选 - `TIMEOUT_MS` 超时,单位毫秒,可选 @@ -208,6 +209,8 @@ services: OPENAI_ACCESS_TOKEN: xxxxxx # API接口地址,可选,设置 OPENAI_API_KEY 时可用 OPENAI_API_BASE_URL: xxxx + # API模型,可选,设置 OPENAI_API_KEY 时可用 + OPENAI_API_Model: xxxx # 反向代理,可选 API_REVERSE_PROXY: xxx # 访问权限密钥,可选 @@ -220,6 +223,7 @@ services: SOCKS_PROXY_PORT: xxxx ``` - `OPENAI_API_BASE_URL` 可选,设置 `OPENAI_API_KEY` 时可用 +- `OPENAI_API_Model` 可选,设置 `OPENAI_API_KEY` 时可用 ### 使用 Railway 部署 [![Deploy on Railway](https://railway.app/button.svg)](https://railway.app/new/template/yytmgc) @@ -234,6 +238,7 @@ services: | `OPENAI_API_KEY` | `OpenAI API` 二选一 | 使用 `OpenAI API` 所需的 `apiKey` [(获取 apiKey)](https://platform.openai.com/overview) | | `OPENAI_ACCESS_TOKEN` | `Web API` 二选一 | 使用 `Web API` 所需的 `accessToken` [(获取 accessToken)](https://chat.openai.com/api/auth/session) | | `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代理端口 | diff --git a/docker-compose/docker-compose.yml b/docker-compose/docker-compose.yml index e2eed1ec3b..12b0b34fa1 100644 --- a/docker-compose/docker-compose.yml +++ b/docker-compose/docker-compose.yml @@ -12,6 +12,8 @@ services: OPENAI_ACCESS_TOKEN: xxxxxx # API接口地址,可选,设置 OPENAI_API_KEY 时可用 OPENAI_API_BASE_URL: xxxx + # API模型,可选,设置 OPENAI_API_KEY 时可用 + OPENAI_API_Model: xxxx # 反向代理,可选 API_REVERSE_PROXY: xxx # 访问权限密钥,可选 diff --git a/service/.env b/service/.env index 6a230e16fc..729d356042 100644 --- a/service/.env +++ b/service/.env @@ -7,6 +7,9 @@ OPENAI_ACCESS_TOKEN= # OpenAI API Base URL - https://api.openai.com OPENAI_API_BASE_URL= +# OpenAI API Model - https://platform.openai.com/docs/models +OPENAI_API_Model= + # Reverse Proxy API_REVERSE_PROXY= diff --git a/service/src/chatgpt/index.ts b/service/src/chatgpt/index.ts index b715ca5b10..8641dc755a 100644 --- a/service/src/chatgpt/index.ts +++ b/service/src/chatgpt/index.ts @@ -36,7 +36,7 @@ let api: ChatGPTAPI | ChatGPTUnofficialProxyAPI const options: ChatGPTAPIOptions = { apiKey: process.env.OPENAI_API_KEY, completionParams: { - model: 'gpt-3.5-turbo', + model: process.env.OPENAI_API_Model ?? 'gpt-3.5-turbo', }, debug: false, }