diff --git a/CHANGELOG.md b/CHANGELOG.md index 7d650a0..e0b4ff0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,24 @@ +## v2.9.2 + +`2023-03-04` + +手动部署的同学,务必删除根目录和`service`中的`node_modules`重新安装依赖,降低出现问题的概率,自动部署的不需要做改动。 + +### Feature +- 感谢 [hyln9](https://github.com/Chanzhaoyu/chatgpt-web/pull/247) 添加对渲染 `LaTex` 数学公式的支持 +- 感谢 [ottocsb](https://github.com/Chanzhaoyu/chatgpt-web/pull/227) 添加支持 `webAPP` (苹果添加到主页书签访问)支持 +- 添加 `OPENAI_API_BASE_URL` 可选环境变量[#249] +## Enhancement +- 优化在高分屏上主题内容的最大宽度[#257] +- 现在文字按单词截断[#215][#225] +### BugFix +- 修复动态生成时代码块不能被复制的问题[#251][#260] +- 修复 `iOS` 移动端输入框不会被键盘顶起的问题[#256] +- 修复控制台渲染警告 +## Other +- 更新依赖至最新 +- 修改 `README` 内容 + ## v2.9.1 `2023-03-02` diff --git a/README.md b/README.md index 8c65ff5..8fc438f 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,8 @@ > 声明:此项目只发布于 Github,基于 MIT 协议,免费且作为开源学习使用。并且不会有任何形式的卖号、付费服务、讨论群、讨论组等行为。谨防受骗。 -![cover](./docs/c1-2.8.0.png) -![cover2](./docs/c2-2.8.0.png) +![cover](./docs/c1.png) +![cover2](./docs/c2.png) - [ChatGPT Web](#chatgpt-web) - [介绍](#介绍) @@ -38,11 +38,11 @@ | 方式 | 免费? | 可靠性 | 质量 | | --------------------------------------------- | ------ | ---------- | ---- | -| `ChatGPTAPI(GPT-3)` | 否 | 可靠 | 较笨 | +| `ChatGPTAPI(gpt-3.5-turbo-0301)` | 否 | 可靠 | 相对较笨 | | `ChatGPTUnofficialProxyAPI(网页 accessToken)` | 是 | 相对不可靠 | 聪明 | 对比: -1. `ChatGPTAPI` 使用 `text-davinci-003` 通过官方`OpenAI`补全`API`模拟`ChatGPT`(最稳健的方法,但它不是免费的,并且没有使用针对聊天进行微调的模型) +1. `ChatGPTAPI` 使用 `gpt-3.5-turbo-0301` 通过官方`OpenAI`补全`API`模拟`ChatGPT`(最稳健的方法,但它不是免费的,并且没有使用针对聊天进行微调的模型) 2. `ChatGPTUnofficialProxyAPI` 使用非官方代理服务器访问 `ChatGPT` 的后端`API`,绕过`Cloudflare`(使用真实的的`ChatGPT`,非常轻量级,但依赖于第三方服务器,并且有速率限制) [查看详情](https://github.com/Chanzhaoyu/chatgpt-web/issues/138) @@ -55,13 +55,21 @@ 反向代理: -`ChatGPTUnofficialProxyAPI`时可用 [详情](https://github.com/transitive-bullshit/chatgpt-api#reverse-proxy) +`ChatGPTUnofficialProxyAPI`时可用 ```shell # service/.env API_REVERSE_PROXY= ``` +环境变量: + +全部参数变量请查看或[这里](#docker-参数示例) + +``` +/service/.env +``` + ## 待实现路线 [✓] 双模型 @@ -145,6 +153,7 @@ pnpm dev - `OPENAI_API_KEY` 二选一 - `OPENAI_ACCESS_TOKEN` 二选一,同时存在时,`OPENAI_API_KEY` 优先 +- `OPENAI_API_BASE_URL` 可选,设置 `OPENAI_API_KEY` 时可用 - `API_REVERSE_PROXY` 可选,设置 `OPENAI_ACCESS_TOKEN` 时可用 [参考](#介绍) - `TIMEOUT_MS` 超时,单位毫秒,可选 - `SOCKS_PROXY_HOST` 可选,和 SOCKS_PROXY_PORT 一起时生效 @@ -184,6 +193,8 @@ services: OPENAI_API_KEY: xxxxxx # 二选一 OPENAI_ACCESS_TOKEN: xxxxxx + # API接口地址,可选,设置 OPENAI_API_KEY 时可用 + OPENAI_API_BASE_URL: xxxx # 反向代理,可选 API_REVERSE_PROXY: xxx # 超时,单位毫秒,可选 @@ -193,7 +204,7 @@ services: # Socks代理端口,可选,和 SOCKS_PROXY_HOST 一起时生效 SOCKS_PROXY_PORT: xxxx ``` - +- `OPENAI_API_BASE_URL` 可选,设置 `OPENAI_API_KEY` 时可用 ### 使用 Railway 部署 [![Deploy on Railway](https://railway.app/button.svg)](https://railway.app/new/template/yytmgc) @@ -206,6 +217,7 @@ services: | `TIMEOUT_MS` | 可选 | 超时时间,单位毫秒, | | `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`接口地址 | | `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 7f06dd4..15f8f52 100644 --- a/docker-compose/docker-compose.yml +++ b/docker-compose/docker-compose.yml @@ -10,6 +10,8 @@ services: OPENAI_API_KEY: xxxx # 二选一 OPENAI_ACCESS_TOKEN: xxxxxx + # API接口地址,可选,设置 OPENAI_API_KEY 时可用 + OPENAI_API_BASE_URL: xxxx # 反向代理,可选 API_REVERSE_PROXY: xxx # 超时,单位毫秒,可选 diff --git a/docs/c1.png b/docs/c1.png index 4eefc1a..48dddfa 100644 Binary files a/docs/c1.png and b/docs/c1.png differ diff --git a/docs/c2.png b/docs/c2.png index 88a5a98..10482c8 100644 Binary files a/docs/c2.png and b/docs/c2.png differ diff --git a/docs/cover.png b/docs/cover.png deleted file mode 100644 index 19602eb..0000000 Binary files a/docs/cover.png and /dev/null differ diff --git a/docs/cover2.png b/docs/cover2.png deleted file mode 100644 index 9d801d4..0000000 Binary files a/docs/cover2.png and /dev/null differ diff --git a/package.json b/package.json index 9eff475..b09b1ec 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "chatgpt-web", - "version": "2.9.1", + "version": "2.9.2", "private": false, "description": "ChatGPT Web", "author": "ChenZhaoYu ", @@ -41,7 +41,7 @@ "@types/crypto-js": "^4.1.1", "@types/katex": "^0.16.0", "@types/marked": "^4.0.8", - "@types/node": "^18.14.4", + "@types/node": "^18.14.6", "@vitejs/plugin-vue": "^4.0.0", "autoprefixer": "^10.4.13", "axios": "^1.3.4", @@ -52,7 +52,7 @@ "lint-staged": "^13.1.2", "npm-run-all": "^4.1.5", "postcss": "^8.4.21", - "rimraf": "^4.1.3", + "rimraf": "^4.2.0", "tailwindcss": "^3.2.7", "typescript": "~4.9.5", "vite": "^4.1.4", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 90f3395..0649d8b 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -8,7 +8,7 @@ specifiers: '@types/crypto-js': ^4.1.1 '@types/katex': ^0.16.0 '@types/marked': ^4.0.8 - '@types/node': ^18.14.4 + '@types/node': ^18.14.6 '@vitejs/plugin-vue': ^4.0.0 '@vueuse/core': ^9.13.0 autoprefixer: ^10.4.13 @@ -25,7 +25,7 @@ specifiers: npm-run-all: ^4.1.5 pinia: ^2.0.32 postcss: ^8.4.21 - rimraf: ^4.1.3 + rimraf: ^4.2.0 tailwindcss: ^3.2.7 typescript: ~4.9.5 vite: ^4.1.4 @@ -53,7 +53,7 @@ devDependencies: '@types/crypto-js': 4.1.1 '@types/katex': 0.16.0 '@types/marked': 4.0.8 - '@types/node': 18.14.4 + '@types/node': 18.14.6 '@vitejs/plugin-vue': 4.0.0_vite@4.1.4+vue@3.2.47 autoprefixer: 10.4.13_postcss@8.4.21 axios: 1.3.4 @@ -64,10 +64,10 @@ devDependencies: lint-staged: 13.1.2 npm-run-all: 4.1.5 postcss: 8.4.21 - rimraf: 4.1.3 + rimraf: 4.2.0 tailwindcss: 3.2.7_postcss@8.4.21 typescript: 4.9.5 - vite: 4.1.4_752grm4nw4hff7lyew72esoj4m + vite: 4.1.4_4l5pdn5ozbjpiwj3fcgseihr44 vue-tsc: 1.2.0_typescript@4.9.5 packages: @@ -293,15 +293,15 @@ packages: '@commitlint/execute-rule': 17.4.0 '@commitlint/resolve-extends': 17.4.4 '@commitlint/types': 17.4.4 - '@types/node': 18.14.4 + '@types/node': 18.14.6 chalk: 4.1.2 cosmiconfig: 8.1.0 - cosmiconfig-typescript-loader: 4.3.0_nd25hbh3ectnnkbvturxnqqqfm + cosmiconfig-typescript-loader: 4.3.0_y2okb5cfqgxv537umje5rj3w6m lodash.isplainobject: 4.0.6 lodash.merge: 4.6.2 lodash.uniq: 4.5.0 resolve-from: 5.0.0 - ts-node: 10.9.1_oboltcrkaqheaa54woelu7cdsa + ts-node: 10.9.1_alpjt73dvgv6kni625hu7f2l4m typescript: 4.9.5 transitivePeerDependencies: - '@swc/core' @@ -804,8 +804,8 @@ packages: resolution: {integrity: sha512-jhuKLIRrhvCPLqwPcx6INqmKeiA5EWrsCOPhrlFSrbrmU4ZMPjj5Ul/oLCMDO98XRUIwVm78xICz4EPCektzeQ==} dev: true - /@types/node/18.14.4: - resolution: {integrity: sha512-VhCw7I7qO2X49+jaKcAUwi3rR+hbxT5VcYF493+Z5kMLI0DL568b7JI4IDJaxWFH0D/xwmGJNoXisyX+w7GH/g==} + /@types/node/18.14.6: + resolution: {integrity: sha512-93+VvleD3mXwlLI/xASjw0FzKcwzl3OdTCzm1LaRfqgS21gfFtK3zDXM5Op9TeeMsJVOaJ2VRDpT9q4Y3d0AvA==} dev: true /@types/normalize-package-data/2.4.1: @@ -961,7 +961,7 @@ packages: vite: ^4.0.0 vue: ^3.2.25 dependencies: - vite: 4.1.4_752grm4nw4hff7lyew72esoj4m + vite: 4.1.4_4l5pdn5ozbjpiwj3fcgseihr44 vue: 3.2.47 dev: true @@ -1595,7 +1595,7 @@ packages: is-what: 3.14.1 dev: true - /cosmiconfig-typescript-loader/4.3.0_nd25hbh3ectnnkbvturxnqqqfm: + /cosmiconfig-typescript-loader/4.3.0_y2okb5cfqgxv537umje5rj3w6m: resolution: {integrity: sha512-NTxV1MFfZDLPiBMjxbHRwSh5LaLcPMwNdCutmnHJCKoVnlvldPWlllonKwrsRJ5pYZBIBGRWWU2tfvzxgeSW5Q==} engines: {node: '>=12', npm: '>=6'} peerDependencies: @@ -1604,9 +1604,9 @@ packages: ts-node: '>=10' typescript: '>=3' dependencies: - '@types/node': 18.14.4 + '@types/node': 18.14.6 cosmiconfig: 8.1.0 - ts-node: 10.9.1_oboltcrkaqheaa54woelu7cdsa + ts-node: 10.9.1_alpjt73dvgv6kni625hu7f2l4m typescript: 4.9.5 dev: true @@ -2607,6 +2607,16 @@ packages: path-is-absolute: 1.0.1 dev: true + /glob/9.2.1: + resolution: {integrity: sha512-Pxxgq3W0HyA3XUvSXcFhRSs+43Jsx0ddxcFrbjxNGkL2Ak5BAUBxLqI5G6ADDeCHLfzzXFhe0b1yYcctGmytMA==} + engines: {node: '>=16 || 14 >=14.17'} + dependencies: + fs.realpath: 1.0.0 + minimatch: 7.4.2 + minipass: 4.2.4 + path-scurry: 1.6.1 + dev: true + /global-dirs/0.1.1: resolution: {integrity: sha512-NknMLn7F2J7aflwFOlGdNIuCDpN3VGoSoB+aap3KABFWbHVn1TCgFC+np23J8W2BiZbjfEw3BFBycSMv1AFblg==} engines: {node: '>=4'} @@ -3273,6 +3283,11 @@ packages: yallist: 4.0.0 dev: true + /lru-cache/7.18.1: + resolution: {integrity: sha512-8/HcIENyQnfUTCDizRu9rrDyG6XG/21M4X7/YEGZeD76ZJilFPAUVb/2zysFf7VVO1LEjCDFyHp8pMMvozIrvg==} + engines: {node: '>=12'} + dev: true + /magic-string/0.25.9: resolution: {integrity: sha512-RmF0AsMzgt25qzqqLc1+MbHmhdx0ojF2Fvs4XnOqz2ZOBXzzkEwc/dJQZCYHAn7v1jbVOjAZfK8msRn4BxO4VQ==} dependencies: @@ -3420,6 +3435,13 @@ packages: brace-expansion: 2.0.1 dev: true + /minimatch/7.4.2: + resolution: {integrity: sha512-xy4q7wou3vUoC9k1xGTXc+awNdGaGVHtFUaey8tiX4H1QRc04DZ/rmDFwNm2EBsuYEhAZ6SgMmYf3InGY6OauA==} + engines: {node: '>=10'} + dependencies: + brace-expansion: 2.0.1 + dev: true + /minimist-options/4.1.0: resolution: {integrity: sha512-Q4r8ghd80yhO/0j1O3B2BjweX3fiHg9cdOwjJd2J76Q135c+NDxGCqdYKQ1SKBuFfgWbAUzBfvYjPUEeNgqN1A==} engines: {node: '>= 6'} @@ -3433,6 +3455,11 @@ packages: resolution: {integrity: sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==} dev: true + /minipass/4.2.4: + resolution: {integrity: sha512-lwycX3cBMTvcejsHITUgYj6Gy6A7Nh4Q6h9NP4sTHY1ccJlC7yKzDmiShEHsJ16Jf1nKGDEaiHxiltsJEvk0nQ==} + engines: {node: '>=8'} + dev: true + /ms/2.1.2: resolution: {integrity: sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==} dev: true @@ -3746,6 +3773,14 @@ packages: resolution: {integrity: sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==} dev: true + /path-scurry/1.6.1: + resolution: {integrity: sha512-OW+5s+7cw6253Q4E+8qQ/u1fVvcJQCJo/VFD8pje+dbJCF1n5ZRMV2AEHbGp+5Q7jxQIYJxkHopnj6nzdGeZLA==} + engines: {node: '>=14'} + dependencies: + lru-cache: 7.18.1 + minipass: 4.2.4 + dev: true + /path-type/3.0.0: resolution: {integrity: sha512-T2ZUsdZFHgA3u4e5PfPbjd7HDDpxPnQb5jN0SrDsjNSuVXHJqtwTnWqG0B1jZrgmJ/7lj1EmVIByWt1gxGkWvg==} engines: {node: '>=4'} @@ -4068,10 +4103,12 @@ packages: glob: 7.2.3 dev: true - /rimraf/4.1.3: - resolution: {integrity: sha512-iyzalDLo3l5FZxxaIGUY7xI4Bf90Xt7pCipc1Mr7RsdU7H3538z+M0tlsUDrz0aHeGS9uNqiKHUJyTewwRP91Q==} + /rimraf/4.2.0: + resolution: {integrity: sha512-tPt+gLORNVqRCk0NwuJ5SlMEcOGvt4CCU8sUPqgCFtCbnoNCTd9Q6vq7JlBbxQlACiH14OR28y7piA2Bak9Sxw==} engines: {node: '>=14'} hasBin: true + dependencies: + glob: 9.2.1 dev: true /rollup/3.18.0: @@ -4442,7 +4479,7 @@ packages: engines: {node: '>=8'} dev: true - /ts-node/10.9.1_oboltcrkaqheaa54woelu7cdsa: + /ts-node/10.9.1_alpjt73dvgv6kni625hu7f2l4m: resolution: {integrity: sha512-NtVysVPkxxrwFGUUxGYhfux8k78pQB3JqYBXlLRZgdGUqTO5wU/UyHop5p70iEbGhB7q5KmiZiU0Y3KlJrScEw==} hasBin: true peerDependencies: @@ -4461,7 +4498,7 @@ packages: '@tsconfig/node12': 1.0.11 '@tsconfig/node14': 1.0.3 '@tsconfig/node16': 1.0.3 - '@types/node': 18.14.4 + '@types/node': 18.14.6 acorn: 8.8.2 acorn-walk: 8.2.0 arg: 4.1.3 @@ -4606,7 +4643,7 @@ packages: vue: 3.2.47 dev: false - /vite/4.1.4_752grm4nw4hff7lyew72esoj4m: + /vite/4.1.4_4l5pdn5ozbjpiwj3fcgseihr44: resolution: {integrity: sha512-3knk/HsbSTKEin43zHu7jTwYWv81f8kgAL99G5NWBcA1LKvtvcVAC4JjBH1arBunO9kQka+1oGbrMKOjk4ZrBg==} engines: {node: ^14.18.0 || >=16.0.0} hasBin: true @@ -4631,7 +4668,7 @@ packages: terser: optional: true dependencies: - '@types/node': 18.14.4 + '@types/node': 18.14.6 esbuild: 0.16.17 less: 4.1.3 postcss: 8.4.21 diff --git a/service/.env b/service/.env index 75cefc4..1df63e9 100644 --- a/service/.env +++ b/service/.env @@ -4,13 +4,16 @@ OPENAI_API_KEY= # change this to an `accessToken` extracted from the ChatGPT site's `https://chat.openai.com/api/auth/session` response OPENAI_ACCESS_TOKEN= +# OpenAI API Base URL - https://api.openai.com +OPENAI_API_BASE_URL= + # Reverse Proxy API_REVERSE_PROXY= # timeout TIMEOUT_MS=100000 -# Socks Proxy Port +# Socks Proxy Host SOCKS_PROXY_HOST= # Socks Proxy Port diff --git a/service/package.json b/service/package.json index b904e8e..8064fc5 100644 --- a/service/package.json +++ b/service/package.json @@ -24,7 +24,7 @@ "common:cleanup": "rimraf node_modules && rimraf pnpm-lock.yaml" }, "dependencies": { - "chatgpt": "^5.0.4", + "chatgpt": "^5.0.6", "dotenv": "^16.0.3", "esno": "^0.16.3", "express": "^4.18.2", @@ -35,9 +35,9 @@ "devDependencies": { "@antfu/eslint-config": "^0.35.3", "@types/express": "^4.17.17", - "@types/node": "^18.14.4", + "@types/node": "^18.14.6", "eslint": "^8.35.0", - "rimraf": "^4.1.3", + "rimraf": "^4.2.0", "tsup": "^6.6.3", "typescript": "^4.9.5" } diff --git a/service/pnpm-lock.yaml b/service/pnpm-lock.yaml index fa76615..c74eb2e 100644 --- a/service/pnpm-lock.yaml +++ b/service/pnpm-lock.yaml @@ -3,21 +3,21 @@ lockfileVersion: 5.4 specifiers: '@antfu/eslint-config': ^0.35.3 '@types/express': ^4.17.17 - '@types/node': ^18.14.4 - chatgpt: ^5.0.4 + '@types/node': ^18.14.6 + chatgpt: ^5.0.6 dotenv: ^16.0.3 eslint: ^8.35.0 esno: ^0.16.3 express: ^4.18.2 isomorphic-fetch: ^3.0.0 node-fetch: ^3.3.0 - rimraf: ^4.1.3 + rimraf: ^4.2.0 socks-proxy-agent: ^7.0.0 tsup: ^6.6.3 typescript: ^4.9.5 dependencies: - chatgpt: 5.0.4 + chatgpt: 5.0.6 dotenv: 16.0.3 esno: 0.16.3 express: 4.18.2 @@ -28,9 +28,9 @@ dependencies: devDependencies: '@antfu/eslint-config': 0.35.3_ycpbpc6yetojsgtrx3mwntkhsu '@types/express': 4.17.17 - '@types/node': 18.14.4 + '@types/node': 18.14.6 eslint: 8.35.0 - rimraf: 4.1.3 + rimraf: 4.2.0 tsup: 6.6.3_typescript@4.9.5 typescript: 4.9.5 @@ -428,19 +428,19 @@ packages: resolution: {integrity: sha512-ALYone6pm6QmwZoAgeyNksccT9Q4AWZQ6PvfwR37GT6r6FWUPguq6sUmNGSMV2Wr761oQoBxwGGa6DR5o1DC9g==} dependencies: '@types/connect': 3.4.35 - '@types/node': 18.14.4 + '@types/node': 18.14.6 dev: true /@types/connect/3.4.35: resolution: {integrity: sha512-cdeYyv4KWoEgpBISTxWvqYsVy444DOqehiF3fM3ne10AmJ62RSyNkUnxMJXHQWRQQX2eR94m5y1IZyDwBjV9FQ==} dependencies: - '@types/node': 18.14.4 + '@types/node': 18.14.6 dev: true /@types/express-serve-static-core/4.17.33: resolution: {integrity: sha512-TPBqmR/HRYI3eC2E5hmiivIzv+bidAfXofM+sbonAGvyDhySGw9/PQZFt2BLOrjUUR++4eJVpx6KnLQK1Fk9tA==} dependencies: - '@types/node': 18.14.4 + '@types/node': 18.14.6 '@types/qs': 6.9.7 '@types/range-parser': 1.2.4 dev: true @@ -472,8 +472,8 @@ packages: resolution: {integrity: sha512-Y4XFY5VJAuw0FgAqPNd6NNoV44jbq9Bz2L7Rh/J6jLTiHBSBJa9fxqQIvkIld4GsoDOcCbvzOUAbLPsSKKg+uA==} dev: true - /@types/node/18.14.4: - resolution: {integrity: sha512-VhCw7I7qO2X49+jaKcAUwi3rR+hbxT5VcYF493+Z5kMLI0DL568b7JI4IDJaxWFH0D/xwmGJNoXisyX+w7GH/g==} + /@types/node/18.14.6: + resolution: {integrity: sha512-93+VvleD3mXwlLI/xASjw0FzKcwzl3OdTCzm1LaRfqgS21gfFtK3zDXM5Op9TeeMsJVOaJ2VRDpT9q4Y3d0AvA==} dev: true /@types/normalize-package-data/2.4.1: @@ -495,7 +495,7 @@ packages: resolution: {integrity: sha512-z5xyF6uh8CbjAu9760KDKsH2FcDxZ2tFCsA4HIMWE6IkiYMXfVoa+4f9KX+FN0ZLsaMw1WNG2ETLA6N+/YA+cg==} dependencies: '@types/mime': 3.0.1 - '@types/node': 18.14.4 + '@types/node': 18.14.6 dev: true /@types/unist/2.0.6: @@ -816,6 +816,12 @@ packages: concat-map: 0.0.1 dev: true + /brace-expansion/2.0.1: + resolution: {integrity: sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==} + dependencies: + balanced-match: 1.0.2 + dev: true + /braces/3.0.2: resolution: {integrity: sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==} engines: {node: '>=8'} @@ -896,8 +902,8 @@ packages: resolution: {integrity: sha512-mKKUkUbhPpQlCOfIuZkvSEgktjPFIsZKRRbC6KWVEMvlzblj3i3asQv5ODsrwt0N3pHAEvjP8KTQPHkp0+6jOg==} dev: true - /chatgpt/5.0.4: - resolution: {integrity: sha512-qkppO2IDYDJC1eaXfqupXdZcOPNqtBkToRcvr9CAGM1rdsKfBDpWLTx4Y6OMNH02sgWu48aJB//0lO1M17K58w==} + /chatgpt/5.0.6: + resolution: {integrity: sha512-BQ0eN2GpAlw9ojsxkHmW+bTuekbllZbOkKqjDSIVSMtbMoYDx59vcg6xXnCPkB0OBFGuG89eqGhLAfMIW34Hcw==} engines: {node: '>=14'} hasBin: true dependencies: @@ -1955,6 +1961,16 @@ packages: path-is-absolute: 1.0.1 dev: true + /glob/9.2.1: + resolution: {integrity: sha512-Pxxgq3W0HyA3XUvSXcFhRSs+43Jsx0ddxcFrbjxNGkL2Ak5BAUBxLqI5G6ADDeCHLfzzXFhe0b1yYcctGmytMA==} + engines: {node: '>=16 || 14 >=14.17'} + dependencies: + fs.realpath: 1.0.0 + minimatch: 7.4.2 + minipass: 4.2.4 + path-scurry: 1.6.1 + dev: true + /globals/13.20.0: resolution: {integrity: sha512-Qg5QtVkCy/kv3FUSlu4ukeZDVf9ee0iXLAUYX13gbR17bnejFTzr4iS9bY7kwCf1NztRNm1t91fjOiyx4CSwPQ==} engines: {node: '>=8'} @@ -2439,6 +2455,11 @@ packages: dependencies: yallist: 4.0.0 + /lru-cache/7.18.1: + resolution: {integrity: sha512-8/HcIENyQnfUTCDizRu9rrDyG6XG/21M4X7/YEGZeD76ZJilFPAUVb/2zysFf7VVO1LEjCDFyHp8pMMvozIrvg==} + engines: {node: '>=12'} + dev: true + /mdast-util-from-markdown/0.8.5: resolution: {integrity: sha512-2hkTXtYYnr+NubD/g6KGBS/0mFmBcifAsI0yIWRiRo0PjVs6SSOSOdtzbp6kSGnShDN6G5aWZpKQ2lWRy27mWQ==} dependencies: @@ -2534,10 +2555,22 @@ packages: brace-expansion: 1.1.11 dev: true + /minimatch/7.4.2: + resolution: {integrity: sha512-xy4q7wou3vUoC9k1xGTXc+awNdGaGVHtFUaey8tiX4H1QRc04DZ/rmDFwNm2EBsuYEhAZ6SgMmYf3InGY6OauA==} + engines: {node: '>=10'} + dependencies: + brace-expansion: 2.0.1 + dev: true + /minimist/1.2.8: resolution: {integrity: sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==} dev: true + /minipass/4.2.4: + resolution: {integrity: sha512-lwycX3cBMTvcejsHITUgYj6Gy6A7Nh4Q6h9NP4sTHY1ccJlC7yKzDmiShEHsJ16Jf1nKGDEaiHxiltsJEvk0nQ==} + engines: {node: '>=8'} + dev: true + /ms/2.0.0: resolution: {integrity: sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==} dev: false @@ -2804,6 +2837,14 @@ packages: resolution: {integrity: sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==} dev: true + /path-scurry/1.6.1: + resolution: {integrity: sha512-OW+5s+7cw6253Q4E+8qQ/u1fVvcJQCJo/VFD8pje+dbJCF1n5ZRMV2AEHbGp+5Q7jxQIYJxkHopnj6nzdGeZLA==} + engines: {node: '>=14'} + dependencies: + lru-cache: 7.18.1 + minipass: 4.2.4 + dev: true + /path-to-regexp/0.1.7: resolution: {integrity: sha512-5DFkuoqlv1uYQKxy8omFBeJPQcdoE07Kv2sferDCrAq1ohOU+MSDswDIbnx3YAM60qIOnYa53wBhXW0EbMonrQ==} dev: false @@ -3007,10 +3048,12 @@ packages: glob: 7.2.3 dev: true - /rimraf/4.1.3: - resolution: {integrity: sha512-iyzalDLo3l5FZxxaIGUY7xI4Bf90Xt7pCipc1Mr7RsdU7H3538z+M0tlsUDrz0aHeGS9uNqiKHUJyTewwRP91Q==} + /rimraf/4.2.0: + resolution: {integrity: sha512-tPt+gLORNVqRCk0NwuJ5SlMEcOGvt4CCU8sUPqgCFtCbnoNCTd9Q6vq7JlBbxQlACiH14OR28y7piA2Bak9Sxw==} engines: {node: '>=14'} hasBin: true + dependencies: + glob: 9.2.1 dev: true /rollup/3.15.0: diff --git a/service/src/chatgpt/index.ts b/service/src/chatgpt/index.ts index 80f8ecc..76e2227 100644 --- a/service/src/chatgpt/index.ts +++ b/service/src/chatgpt/index.ts @@ -1,11 +1,11 @@ import * as dotenv from 'dotenv' import 'isomorphic-fetch' -import type { ChatMessage, SendMessageOptions } from 'chatgpt' +import type { ChatGPTAPIOptions, ChatMessage, SendMessageOptions } from 'chatgpt' import { ChatGPTAPI, ChatGPTUnofficialProxyAPI } from 'chatgpt' import { SocksProxyAgent } from 'socks-proxy-agent' import fetch from 'node-fetch' import { sendResponse } from '../utils' -import type { ApiModel, ChatContext, ChatGPTAPIOptions, ChatGPTUnofficialProxyAPIOptions, ModelConfig } from '../types' +import type { ApiModel, ChatContext, ChatGPTUnofficialProxyAPIOptions, ModelConfig } from '../types' dotenv.config() @@ -18,7 +18,6 @@ if (!process.env.OPENAI_API_KEY && !process.env.OPENAI_ACCESS_TOKEN) let api: ChatGPTAPI | ChatGPTUnofficialProxyAPI -// To use ESM in CommonJS, you can use a dynamic import (async () => { // More Info: https://github.com/transitive-bullshit/chatgpt-api @@ -27,17 +26,21 @@ let api: ChatGPTAPI | ChatGPTUnofficialProxyAPI apiKey: process.env.OPENAI_API_KEY, debug: false, } - let fetchFn + + if (process.env.OPENAI_API_BASE_URL && process.env.OPENAI_API_BASE_URL.trim().length > 0) + options.apiBaseUrl = process.env.OPENAI_API_BASE_URL + if (process.env.SOCKS_PROXY_HOST && process.env.SOCKS_PROXY_PORT) { const agent = new SocksProxyAgent({ hostname: process.env.SOCKS_PROXY_HOST, port: process.env.SOCKS_PROXY_PORT, }) - fetchFn = (url, options) => { + options.fetch = (url, options) => { return fetch(url, { agent, ...options }) } } - api = new ChatGPTAPI({ ...options, fetch: fetchFn }) + + api = new ChatGPTAPI({ ...options }) apiModel = 'ChatGPTAPI' } else { @@ -59,10 +62,7 @@ let api: ChatGPTAPI | ChatGPTUnofficialProxyAPI if (process.env.API_REVERSE_PROXY) options.apiReverseProxyUrl = process.env.API_REVERSE_PROXY - api = new ChatGPTUnofficialProxyAPI({ - accessToken: process.env.OPENAI_ACCESS_TOKEN, - ...options, - }) + api = new ChatGPTUnofficialProxyAPI({ ...options }) apiModel = 'ChatGPTUnofficialProxyAPI' } })() diff --git a/service/src/types.ts b/service/src/types.ts index 9e4ef41..dcade0c 100644 --- a/service/src/types.ts +++ b/service/src/types.ts @@ -1,16 +1,10 @@ -import type { FetchFn, openai } from 'chatgpt' +import type { FetchFn } from 'chatgpt' export interface ChatContext { conversationId?: string parentMessageId?: string } -export interface ChatGPTAPIOptions { - apiKey: string - debug?: boolean - completionParams?: Partial -} - export interface ChatGPTUnofficialProxyAPIOptions { accessToken: string apiReverseProxyUrl?: string diff --git a/src/views/chat/components/Message/Text.vue b/src/views/chat/components/Message/Text.vue index 5d3cd5c..15fe064 100644 --- a/src/views/chat/components/Message/Text.vue +++ b/src/views/chat/components/Message/Text.vue @@ -30,7 +30,7 @@ renderer.code = (code, language) => { const validLang = !!(language && hljs.getLanguage(language)) if (validLang) { const lang = language ?? '' - return `
${lang}${t('chat.copyCode')}
${hljs.highlight(lang, code).value}
` + return `
${lang}${t('chat.copyCode')}
${hljs.highlight(code, { language: lang }).value}
` } return `
${hljs.highlightAuto(code).value}
` } @@ -118,7 +118,7 @@ defineExpose({ textRef })