From b8ea546b3fd27ac104b04ba96c05198f254ff3ad Mon Sep 17 00:00:00 2001 From: Archer <545436317@qq.com> Date: Mon, 18 Sep 2023 13:37:25 +0800 Subject: [PATCH] v4.2.2 (#312) --- client/package.json | 3 + client/pnpm-lock.yaml | 101 ++++++----- client/src/api/plugins/kb.ts | 23 ++- client/src/components/ChatBox/index.tsx | 165 ++++++++---------- client/src/constants/user.ts | 2 +- client/src/pages/account/components/Info.tsx | 2 +- .../src/pages/account/components/PayModal.tsx | 15 +- client/src/pages/account/index.tsx | 8 +- client/src/pages/api/admin/initv442.ts | 27 +++ .../pages/api/core/dataset/file/delById.ts | 9 +- client/src/pages/api/openapi/postKey.ts | 2 +- .../pages/api/openapi/v1/chat/completions.ts | 2 +- .../pages/api/openapi/v1/chat/getHistory.ts | 5 +- .../data/{exportModelData.ts => exportAll.ts} | 69 +++++--- .../src/pages/app/detail/components/API.tsx | 6 +- .../app/detail/components/KBSelectModal.tsx | 5 +- client/src/pages/app/detail/index.tsx | 5 +- .../src/pages/chat/components/ChatHeader.tsx | 2 +- .../pages/kb/detail/components/Import/Csv.tsx | 2 +- .../detail/components/Import/FileSelect.tsx | 20 ++- client/src/pages/kb/list/index.tsx | 18 +- .../pages/login/components/RegisterForm.tsx | 14 +- client/src/pages/login/index.tsx | 2 +- client/src/service/models/bill.ts | 2 +- client/src/types/index.d.ts | 4 +- 25 files changed, 288 insertions(+), 225 deletions(-) create mode 100644 client/src/pages/api/admin/initv442.ts rename client/src/pages/api/plugins/kb/data/{exportModelData.ts => exportAll.ts} (52%) diff --git a/client/package.json b/client/package.json index db4a76b745d..76cfbe95d72 100644 --- a/client/package.json +++ b/client/package.json @@ -23,6 +23,7 @@ "crypto": "^1.0.1", "date-fns": "^2.30.0", "dayjs": "^1.11.7", + "downloadjs": "^1.4.7", "echarts": "^5.4.1", "echarts-gl": "^2.0.9", "formidable": "^2.1.1", @@ -48,6 +49,7 @@ "openai": "^3.3.0", "papaparse": "^5.4.1", "pg": "^8.10.0", + "pg-query-stream": "^4.5.3", "react": "18.2.0", "react-day-picker": "^8.7.1", "react-dom": "18.2.0", @@ -71,6 +73,7 @@ "devDependencies": { "@svgr/webpack": "^6.5.1", "@types/cookie": "^0.5.1", + "@types/downloadjs": "^1.4.3", "@types/formidable": "^2.0.5", "@types/js-cookie": "^3.0.3", "@types/jsdom": "^21.1.1", diff --git a/client/pnpm-lock.yaml b/client/pnpm-lock.yaml index df937472ba2..413fed08ad0 100644 --- a/client/pnpm-lock.yaml +++ b/client/pnpm-lock.yaml @@ -1,4 +1,8 @@ -lockfileVersion: '6.0' +lockfileVersion: '6.1' + +settings: + autoInstallPeers: true + excludeLinksFromLockfile: false dependencies: '@chakra-ui/icons': @@ -43,6 +47,9 @@ dependencies: dayjs: specifier: ^1.11.7 version: registry.npmmirror.com/dayjs@1.11.7 + downloadjs: + specifier: ^1.4.7 + version: registry.npmmirror.com/downloadjs@1.4.7 echarts: specifier: ^5.4.1 version: registry.npmmirror.com/echarts@5.4.1 @@ -99,7 +106,7 @@ dependencies: version: registry.npmmirror.com/nanoid@4.0.1 next: specifier: 13.1.6 - version: registry.npmmirror.com/next@13.1.6(react-dom@18.2.0)(react@18.2.0)(sass@1.58.3) + version: registry.npmmirror.com/next@13.1.6(@babel/core@7.22.5)(react-dom@18.2.0)(react@18.2.0)(sass@1.58.3) next-i18next: specifier: ^13.3.0 version: registry.npmmirror.com/next-i18next@13.3.0(i18next@22.5.1)(next@13.1.6)(react-i18next@12.3.1)(react@18.2.0) @@ -118,6 +125,9 @@ dependencies: pg: specifier: ^8.10.0 version: registry.npmmirror.com/pg@8.10.0 + pg-query-stream: + specifier: ^4.5.3 + version: registry.npmmirror.com/pg-query-stream@4.5.3(pg@8.10.0) react: specifier: 18.2.0 version: registry.npmmirror.com/react@18.2.0 @@ -183,6 +193,9 @@ devDependencies: '@types/cookie': specifier: ^0.5.1 version: registry.npmmirror.com/@types/cookie@0.5.1 + '@types/downloadjs': + specifier: ^1.4.3 + version: registry.npmmirror.com/@types/downloadjs@1.4.3 '@types/formidable': specifier: ^2.0.5 version: registry.npmmirror.com/@types/formidable@2.0.5 @@ -245,7 +258,6 @@ packages: dependencies: '@jridgewell/gen-mapping': registry.npmmirror.com/@jridgewell/gen-mapping@0.3.3 '@jridgewell/trace-mapping': registry.npmmirror.com/@jridgewell/trace-mapping@0.3.18 - dev: true registry.npmmirror.com/@aws-crypto/crc32@3.0.0: resolution: {integrity: sha512-IzSgsrxUcsrejQbPVilIKy16kAT52EwB6zSaI+M3xxIhKh5+aldEyvI+z6erM7TCLB2BJsFrtHjp6/4/sr+3dA==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/@aws-crypto/crc32/-/crc32-3.0.0.tgz} @@ -1226,7 +1238,6 @@ packages: name: '@babel/compat-data' version: 7.22.5 engines: {node: '>=6.9.0'} - dev: true registry.npmmirror.com/@babel/core@7.22.5: resolution: {integrity: sha512-SBuTAjg91A3eKOvD+bPEz3LlhHZRNu1nFOVts9lzDJTXshHTjII0BAtDS3Y2DAkdZdDKWVZGVwkDfc4Clxn1dg==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/@babel/core/-/core-7.22.5.tgz} @@ -1251,7 +1262,6 @@ packages: semver: registry.npmmirror.com/semver@6.3.0 transitivePeerDependencies: - supports-color - dev: true registry.npmmirror.com/@babel/generator@7.22.5: resolution: {integrity: sha512-+lcUbnTRhd0jOewtFSedLyiPsD5tswKkbgcezOqqWFUVNEwoUTlpPOBmvhG7OXWLR4jMdv0czPGH5XbflnD1EA==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/@babel/generator/-/generator-7.22.5.tgz} @@ -1263,7 +1273,6 @@ packages: '@jridgewell/gen-mapping': registry.npmmirror.com/@jridgewell/gen-mapping@0.3.3 '@jridgewell/trace-mapping': registry.npmmirror.com/@jridgewell/trace-mapping@0.3.18 jsesc: registry.npmmirror.com/jsesc@2.5.2 - dev: true registry.npmmirror.com/@babel/helper-annotate-as-pure@7.22.5: resolution: {integrity: sha512-LvBTxu8bQSQkcyKOU+a1btnNFQ1dMAd0R6PyW3arXes06F6QLWLIrd681bxRPIXlrMGR3XYnW9JyML7dP3qgxg==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/@babel/helper-annotate-as-pure/-/helper-annotate-as-pure-7.22.5.tgz} @@ -1298,7 +1307,6 @@ packages: browserslist: registry.npmmirror.com/browserslist@4.21.7 lru-cache: registry.npmmirror.com/lru-cache@5.1.1 semver: registry.npmmirror.com/semver@6.3.0 - dev: true registry.npmmirror.com/@babel/helper-create-class-features-plugin@7.22.5(@babel/core@7.22.5): resolution: {integrity: sha512-xkb58MyOYIslxu3gKmVXmjTtUPvBU4odYzbiIQbWwLKIHCsx6UGZGX6F1IznMFVnDdirseUZopzN+ZRt8Xb33Q==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/@babel/helper-create-class-features-plugin/-/helper-create-class-features-plugin-7.22.5.tgz} @@ -1362,7 +1370,6 @@ packages: name: '@babel/helper-environment-visitor' version: 7.22.5 engines: {node: '>=6.9.0'} - dev: true registry.npmmirror.com/@babel/helper-function-name@7.22.5: resolution: {integrity: sha512-wtHSq6jMRE3uF2otvfuD3DIvVhOsSNshQl0Qrd7qC9oQJzHvOL4qQXlQn2916+CXGywIjpGuIkoyZRRxHPiNQQ==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/@babel/helper-function-name/-/helper-function-name-7.22.5.tgz} @@ -1372,7 +1379,6 @@ packages: dependencies: '@babel/template': registry.npmmirror.com/@babel/template@7.22.5 '@babel/types': registry.npmmirror.com/@babel/types@7.22.5 - dev: true registry.npmmirror.com/@babel/helper-hoist-variables@7.22.5: resolution: {integrity: sha512-wGjk9QZVzvknA6yKIUURb8zY3grXCcOZt+/7Wcy8O2uctxhplmUPkOdlgoNhmdVee2c92JXbf1xpMtVNbfoxRw==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/@babel/helper-hoist-variables/-/helper-hoist-variables-7.22.5.tgz} @@ -1381,7 +1387,6 @@ packages: engines: {node: '>=6.9.0'} dependencies: '@babel/types': registry.npmmirror.com/@babel/types@7.22.5 - dev: true registry.npmmirror.com/@babel/helper-member-expression-to-functions@7.22.5: resolution: {integrity: sha512-aBiH1NKMG0H2cGZqspNvsaBe6wNGjbJjuLy29aU+eDZjSbbN53BaxlpB02xm9v34pLTZ1nIQPFYn2qMZoa5BQQ==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/@babel/helper-member-expression-to-functions/-/helper-member-expression-to-functions-7.22.5.tgz} @@ -1416,7 +1421,6 @@ packages: '@babel/types': registry.npmmirror.com/@babel/types@7.22.5 transitivePeerDependencies: - supports-color - dev: true registry.npmmirror.com/@babel/helper-optimise-call-expression@7.22.5: resolution: {integrity: sha512-HBwaojN0xFRx4yIvpwGqxiV2tUfl7401jlok564NgB9EHS1y6QT17FmKWm4ztqjeVdXLuC4fSvHc5ePpQjoTbw==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/@babel/helper-optimise-call-expression/-/helper-optimise-call-expression-7.22.5.tgz} @@ -1475,7 +1479,6 @@ packages: engines: {node: '>=6.9.0'} dependencies: '@babel/types': registry.npmmirror.com/@babel/types@7.22.5 - dev: true registry.npmmirror.com/@babel/helper-skip-transparent-expression-wrappers@7.22.5: resolution: {integrity: sha512-tK14r66JZKiC43p8Ki33yLBVJKlQDFoA8GYN67lWCDCqoL6EMMSuM9b+Iff2jHaM/RRFYl7K+iiru7hbRqNx8Q==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/@babel/helper-skip-transparent-expression-wrappers/-/helper-skip-transparent-expression-wrappers-7.22.5.tgz} @@ -1493,7 +1496,6 @@ packages: engines: {node: '>=6.9.0'} dependencies: '@babel/types': registry.npmmirror.com/@babel/types@7.22.5 - dev: true registry.npmmirror.com/@babel/helper-string-parser@7.22.5: resolution: {integrity: sha512-mM4COjgZox8U+JcXQwPijIZLElkgEpO5rsERVDJTc2qfCDfERyob6k5WegS14SX18IIjv+XD+GrqNumY5JRCDw==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/@babel/helper-string-parser/-/helper-string-parser-7.22.5.tgz} @@ -1512,7 +1514,6 @@ packages: name: '@babel/helper-validator-option' version: 7.22.5 engines: {node: '>=6.9.0'} - dev: true registry.npmmirror.com/@babel/helper-wrap-function@7.22.5: resolution: {integrity: sha512-bYqLIBSEshYcYQyfks8ewYA8S30yaGSeRslcvKMvoUk6HHPySbxHq9YRi6ghhzEU+yhQv9bP/jXnygkStOcqZw==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/@babel/helper-wrap-function/-/helper-wrap-function-7.22.5.tgz} @@ -1539,7 +1540,6 @@ packages: '@babel/types': registry.npmmirror.com/@babel/types@7.22.5 transitivePeerDependencies: - supports-color - dev: true registry.npmmirror.com/@babel/highlight@7.22.5: resolution: {integrity: sha512-BSKlD1hgnedS5XRnGOljZawtag7H1yPfQp0tdNJCHoH6AZ+Pcm9VvkrK59/Yy593Ypg0zMxH2BxD1VPYUQ7UIw==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/@babel/highlight/-/highlight-7.22.5.tgz} @@ -1559,7 +1559,6 @@ packages: hasBin: true dependencies: '@babel/types': registry.npmmirror.com/@babel/types@7.22.5 - dev: true registry.npmmirror.com/@babel/plugin-bugfix-safari-id-destructuring-collision-in-function-expression@7.22.5(@babel/core@7.22.5): resolution: {integrity: sha512-NP1M5Rf+u2Gw9qfSO4ihjcTGW5zXTi36ITLd4/EoAcEhIZ0yjMqmftDNl3QC19CX7olhrjpyU454g/2W7X0jvQ==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/@babel/plugin-bugfix-safari-id-destructuring-collision-in-function-expression/-/plugin-bugfix-safari-id-destructuring-collision-in-function-expression-7.22.5.tgz} @@ -2822,7 +2821,6 @@ packages: '@babel/code-frame': registry.npmmirror.com/@babel/code-frame@7.22.5 '@babel/parser': registry.npmmirror.com/@babel/parser@7.22.5 '@babel/types': registry.npmmirror.com/@babel/types@7.22.5 - dev: true registry.npmmirror.com/@babel/traverse@7.22.5: resolution: {integrity: sha512-7DuIjPgERaNo6r+PZwItpjCZEa5vyw4eJGufeLxrPdBXBoLcCJCIasvK6pK/9DVNrLZTLFhUGqaC6X/PA007TQ==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/@babel/traverse/-/traverse-7.22.5.tgz} @@ -2842,7 +2840,6 @@ packages: globals: registry.npmmirror.com/globals@11.12.0 transitivePeerDependencies: - supports-color - dev: true registry.npmmirror.com/@babel/types@7.22.5: resolution: {integrity: sha512-zo3MIHGOkPOfoRXitsgHLjEXmlDaD/5KU1Uzuc9GNiZPhSqVxVRtxuPaSBZDsYZ9qV88AjtMtWW7ww98loJ9KA==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/@babel/types/-/types-7.22.5.tgz} @@ -4430,33 +4427,28 @@ packages: '@jridgewell/set-array': registry.npmmirror.com/@jridgewell/set-array@1.1.2 '@jridgewell/sourcemap-codec': registry.npmmirror.com/@jridgewell/sourcemap-codec@1.4.15 '@jridgewell/trace-mapping': registry.npmmirror.com/@jridgewell/trace-mapping@0.3.18 - dev: true registry.npmmirror.com/@jridgewell/resolve-uri@3.1.0: resolution: {integrity: sha512-F2msla3tad+Mfht5cJq7LSXcdudKTWCVYUgw6pLFOOHSTtZlj6SWNYAp+AhuqLmWdBO2X5hPrLcu8cVP8fy28w==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/@jridgewell/resolve-uri/-/resolve-uri-3.1.0.tgz} name: '@jridgewell/resolve-uri' version: 3.1.0 engines: {node: '>=6.0.0'} - dev: true registry.npmmirror.com/@jridgewell/set-array@1.1.2: resolution: {integrity: sha512-xnkseuNADM0gt2bs+BvhO0p78Mk762YnZdsuzFV018NoG1Sj1SCQvpSqa7XUaTam5vAGasABV9qXASMKnFMwMw==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/@jridgewell/set-array/-/set-array-1.1.2.tgz} name: '@jridgewell/set-array' version: 1.1.2 engines: {node: '>=6.0.0'} - dev: true registry.npmmirror.com/@jridgewell/sourcemap-codec@1.4.14: resolution: {integrity: sha512-XPSJHWmi394fuUuzDnGz1wiKqWfo1yXecHQMRf2l6hztTO+nPru658AyDngaBe7isIxEkRsPR3FZh+s7iVa4Uw==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.4.14.tgz} name: '@jridgewell/sourcemap-codec' version: 1.4.14 - dev: true registry.npmmirror.com/@jridgewell/sourcemap-codec@1.4.15: resolution: {integrity: sha512-eF2rxCRulEKXHTRiDrDy6erMYWqNw4LPdQ8UQA4huuxaQsVeRPFl2oM8oDGxMFhJUWZf9McpLtJasDDZb/Bpeg==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.4.15.tgz} name: '@jridgewell/sourcemap-codec' version: 1.4.15 - dev: true registry.npmmirror.com/@jridgewell/trace-mapping@0.3.18: resolution: {integrity: sha512-w+niJYzMHdd7USdiH2U6869nqhD2nbfZXND5Yp93qIbEmnDNk7PD48o+YchRVpzMU7M6jVCbenTR7PA1FLQ9pA==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/@jridgewell/trace-mapping/-/trace-mapping-0.3.18.tgz} @@ -4465,7 +4457,6 @@ packages: dependencies: '@jridgewell/resolve-uri': registry.npmmirror.com/@jridgewell/resolve-uri@3.1.0 '@jridgewell/sourcemap-codec': registry.npmmirror.com/@jridgewell/sourcemap-codec@1.4.14 - dev: true registry.npmmirror.com/@motionone/animation@10.15.1: resolution: {integrity: sha512-mZcJxLjHor+bhcPuIFErMDNyrdb2vJur8lSfMCsuCB4UyV8ILZLvK+t+pg56erv8ud9xQGK/1OGPt10agPrCyQ==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/@motionone/animation/-/animation-10.15.1.tgz} @@ -5407,6 +5398,12 @@ packages: '@types/ms': registry.npmmirror.com/@types/ms@0.7.31 dev: false + registry.npmmirror.com/@types/downloadjs@1.4.3: + resolution: {integrity: sha512-MjJepFle/tLtT2/jmDNth6ZnwWzEhm40L+olE5HKR70ISUCfgT55eqreeHldAzFLY2HDUGsn8zgyto8KygN0CA==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/@types/downloadjs/-/downloadjs-1.4.3.tgz} + name: '@types/downloadjs' + version: 1.4.3 + dev: true + registry.npmmirror.com/@types/express-serve-static-core@4.17.36: resolution: {integrity: sha512-zbivROJ0ZqLAtMzgzIUC4oNqDG9iF0lSsAqpOD9kbs5xcIM3dTiyuHvBc7R8MtWBp3AAWGaovJa+wzWPjLYW7Q==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/@types/express-serve-static-core/-/express-serve-static-core-4.17.36.tgz} name: '@types/express-serve-static-core' @@ -6194,7 +6191,6 @@ packages: electron-to-chromium: registry.npmmirror.com/electron-to-chromium@1.4.425 node-releases: registry.npmmirror.com/node-releases@2.0.12 update-browserslist-db: registry.npmmirror.com/update-browserslist-db@1.0.11(browserslist@4.21.7) - dev: true registry.npmmirror.com/bson@1.1.6: resolution: {integrity: sha512-EvVNVeGo4tHxwi8L6bPj3y3itEvStdwvvlojVxxbyYfoaxJ6keLgrTuKdyfEAszFK+H3olzBuafE0yoh0D1gdg==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/bson/-/bson-1.1.6.tgz} @@ -7280,6 +7276,12 @@ packages: domhandler: registry.npmmirror.com/domhandler@4.3.1 dev: true + registry.npmmirror.com/downloadjs@1.4.7: + resolution: {integrity: sha512-LN1gO7+u9xjU5oEScGFKvXhYf7Y/empUIIEAGBs1LzUq/rg5duiDrkuH5A2lQGd5jfMOb9X9usDa2oVXwJ0U/Q==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/downloadjs/-/downloadjs-1.4.7.tgz} + name: downloadjs + version: 1.4.7 + dev: false + registry.npmmirror.com/duck@0.1.12: resolution: {integrity: sha512-wkctla1O6VfP89gQ+J/yDesM0S7B7XLXjKGzXxMDVFg7uEn706niAtyYovKbyq1oT9YwDcly721/iUWoc8MVRg==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/duck/-/duck-0.1.12.tgz} name: duck @@ -7322,7 +7324,6 @@ packages: resolution: {integrity: sha512-wv1NufHxu11zfDbY4fglYQApMswleE9FL/DSeyOyauVXDZ+Kco96JK/tPfBUaDqfRarYp2WH2hJ/5UnVywp9Jg==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/electron-to-chromium/-/electron-to-chromium-1.4.425.tgz} name: electron-to-chromium version: 1.4.425 - dev: true registry.npmmirror.com/elkjs@0.8.2: resolution: {integrity: sha512-L6uRgvZTH+4OF5NE/MBbzQx/WYpru1xCBE9respNj6qznEewGUIfhzmm7horWWxbNO2M0WckQypGctR8lH79xQ==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/elkjs/-/elkjs-0.8.2.tgz} @@ -7464,7 +7465,6 @@ packages: name: escalade version: 3.1.1 engines: {node: '>=6'} - dev: true registry.npmmirror.com/escape-string-regexp@1.0.5: resolution: {integrity: sha512-vbRorB5FUQWvla16U8R/qgaFIya2qGzwDrNmCZuYKrbdSUMG6I1ZCGQRefkRVhuOkIGVne7BQ35DSfo1qvJqFg==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz} @@ -8104,7 +8104,6 @@ packages: name: gensync version: 1.0.0-beta.2 engines: {node: '>=6.9.0'} - dev: true registry.npmmirror.com/get-intrinsic@1.2.1: resolution: {integrity: sha512-2DcsyfABl+gVHEfCOaTrWgyt+tb6MSEGmKq+kI5HwLbIYgjgmMcV8KQ41uaKz1xxUcn9tJtgFbQUEVcEbd0FYw==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/get-intrinsic/-/get-intrinsic-1.2.1.tgz} @@ -8196,7 +8195,6 @@ packages: name: globals version: 11.12.0 engines: {node: '>=4'} - dev: true registry.npmmirror.com/globals@13.20.0: resolution: {integrity: sha512-Qg5QtVkCy/kv3FUSlu4ukeZDVf9ee0iXLAUYX13gbR17bnejFTzr4iS9bY7kwCf1NztRNm1t91fjOiyx4CSwPQ==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/globals/-/globals-13.20.0.tgz} @@ -9031,7 +9029,6 @@ packages: version: 2.5.2 engines: {node: '>=4'} hasBin: true - dev: true registry.npmmirror.com/json-parse-even-better-errors@2.3.1: resolution: {integrity: sha512-xyFwyhro/JEof6Ghe2iz2NcXoj2sloNsWr/XsERDK/oiPCfaNhl5ONfp+jQdAZRQQ0IJWNzH9zIZF7li91kh2w==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/json-parse-even-better-errors/-/json-parse-even-better-errors-2.3.1.tgz} @@ -9065,7 +9062,6 @@ packages: version: 2.2.3 engines: {node: '>=6'} hasBin: true - dev: true registry.npmmirror.com/jsonwebtoken@9.0.0: resolution: {integrity: sha512-tuGfYXxkQGDPnLJ7SibiQgVgeDgfbPq2k2ICcbgqW8WxWLBAxKQM/ZCu/IT8SOSwmaYl4dpTFCW5xZv7YbbWUw==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/jsonwebtoken/-/jsonwebtoken-9.0.0.tgz} @@ -9303,7 +9299,6 @@ packages: version: 5.1.1 dependencies: yallist: registry.npmmirror.com/yallist@3.1.1 - dev: true registry.npmmirror.com/lru-cache@6.0.0: resolution: {integrity: sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/lru-cache/-/lru-cache-6.0.0.tgz} @@ -10118,12 +10113,12 @@ packages: hoist-non-react-statics: registry.npmmirror.com/hoist-non-react-statics@3.3.2 i18next: registry.npmmirror.com/i18next@22.5.1 i18next-fs-backend: registry.npmmirror.com/i18next-fs-backend@2.1.5 - next: registry.npmmirror.com/next@13.1.6(react-dom@18.2.0)(react@18.2.0)(sass@1.58.3) + next: registry.npmmirror.com/next@13.1.6(@babel/core@7.22.5)(react-dom@18.2.0)(react@18.2.0)(sass@1.58.3) react: registry.npmmirror.com/react@18.2.0 react-i18next: registry.npmmirror.com/react-i18next@12.3.1(i18next@22.5.1)(react-dom@18.2.0)(react@18.2.0) dev: false - registry.npmmirror.com/next@13.1.6(react-dom@18.2.0)(react@18.2.0)(sass@1.58.3): + registry.npmmirror.com/next@13.1.6(@babel/core@7.22.5)(react-dom@18.2.0)(react@18.2.0)(sass@1.58.3): resolution: {integrity: sha512-hHlbhKPj9pW+Cymvfzc15lvhaOZ54l+8sXDXJWm3OBNBzgrVj6hwGPmqqsXg40xO1Leq+kXpllzRPuncpC0Phw==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/next/-/next-13.1.6.tgz} id: registry.npmmirror.com/next/13.1.6 name: next @@ -10151,7 +10146,7 @@ packages: react: registry.npmmirror.com/react@18.2.0 react-dom: registry.npmmirror.com/react-dom@18.2.0(react@18.2.0) sass: registry.npmmirror.com/sass@1.58.3 - styled-jsx: registry.npmmirror.com/styled-jsx@5.1.1(react@18.2.0) + styled-jsx: registry.npmmirror.com/styled-jsx@5.1.1(@babel/core@7.22.5)(react@18.2.0) optionalDependencies: '@next/swc-android-arm-eabi': registry.npmmirror.com/@next/swc-android-arm-eabi@13.1.6 '@next/swc-android-arm64': registry.npmmirror.com/@next/swc-android-arm64@13.1.6 @@ -10180,14 +10175,13 @@ packages: next: ^8.1.1-canary.54 || ^9.0.0 || ^10.0.0-0 || ^11.0.0 || ^12.0.0 || ^13.0.0 dependencies: cors: registry.npmmirror.com/cors@2.8.5 - next: registry.npmmirror.com/next@13.1.6(react-dom@18.2.0)(react@18.2.0)(sass@1.58.3) + next: registry.npmmirror.com/next@13.1.6(@babel/core@7.22.5)(react-dom@18.2.0)(react@18.2.0)(sass@1.58.3) dev: false registry.npmmirror.com/node-releases@2.0.12: resolution: {integrity: sha512-QzsYKWhXTWx8h1kIvqfnC++o0pEmpRQA/aenALsL2F4pqNVr7YzcdMlDij5WBnwftRbJCNJL/O7zdKaxKPHqgQ==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/node-releases/-/node-releases-2.0.12.tgz} name: node-releases version: 2.0.12 - dev: true registry.npmmirror.com/non-layered-tidy-tree-layout@2.0.2: resolution: {integrity: sha512-gkXMxRzUH+PB0ax9dUN0yYF0S25BqeAYqhgMaLUFmpXLEk7Fcu8f4emJuOAY0V8kjDICxROIKsTAKsV/v355xw==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/non-layered-tidy-tree-layout/-/non-layered-tidy-tree-layout-2.0.2.tgz} @@ -10532,6 +10526,17 @@ packages: version: 2.6.0 dev: false + registry.npmmirror.com/pg-cursor@2.10.3(pg@8.10.0): + resolution: {integrity: sha512-rDyBVoqPVnx/PTmnwQAYgusSeAKlTL++gmpf5klVK+mYMFEqsOc6VHHZnPKc/4lOvr4r6fiMuoxSFuBF1dx4FQ==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/pg-cursor/-/pg-cursor-2.10.3.tgz} + id: registry.npmmirror.com/pg-cursor/2.10.3 + name: pg-cursor + version: 2.10.3 + peerDependencies: + pg: ^8 + dependencies: + pg: registry.npmmirror.com/pg@8.10.0 + dev: false + registry.npmmirror.com/pg-int8@1.0.1: resolution: {integrity: sha512-WCtabS6t3c8SkpDBUlb1kjOs7l66xsGdKpIPZsg4wR+B3+u9UAum2odSsF9tnvxg80h4ZxLWMy4pRjOsFIqQpw==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/pg-int8/-/pg-int8-1.0.1.tgz} name: pg-int8 @@ -10554,6 +10559,18 @@ packages: name: pg-protocol version: 1.6.0 + registry.npmmirror.com/pg-query-stream@4.5.3(pg@8.10.0): + resolution: {integrity: sha512-ufa94r/lHJdjAm3+zPZEO0gXAmCb4tZPaOt7O76mjcxdL/HxwTuryy76km+u0odBBgtfdKFYq/9XGfiYeQF0yA==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/pg-query-stream/-/pg-query-stream-4.5.3.tgz} + id: registry.npmmirror.com/pg-query-stream/4.5.3 + name: pg-query-stream + version: 4.5.3 + peerDependencies: + pg: ^8 + dependencies: + pg: registry.npmmirror.com/pg@8.10.0 + pg-cursor: registry.npmmirror.com/pg-cursor@2.10.3(pg@8.10.0) + dev: false + registry.npmmirror.com/pg-types@2.2.0: resolution: {integrity: sha512-qTAAlrEsl8s4OiEQY69wDvcMIdQN6wdz5ojQiOy6YRMuynxenON0O5oCpJI6lshc6scgAY8qvJ2On/p+CXY0GA==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/pg-types/-/pg-types-2.2.0.tgz} name: pg-types @@ -11374,7 +11391,6 @@ packages: name: semver version: 6.3.0 hasBin: true - dev: true registry.npmmirror.com/semver@7.5.1: resolution: {integrity: sha512-Wvss5ivl8TMRZXXESstBA4uR5iXgEN/VC5/sOcuXdVLzcdkz4HWetIoRfG5gb5X+ij/G9rw9YoGn3QoQ8OCSpw==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/semver/-/semver-7.5.1.tgz} @@ -11658,7 +11674,7 @@ packages: inline-style-parser: registry.npmmirror.com/inline-style-parser@0.1.1 dev: false - registry.npmmirror.com/styled-jsx@5.1.1(react@18.2.0): + registry.npmmirror.com/styled-jsx@5.1.1(@babel/core@7.22.5)(react@18.2.0): resolution: {integrity: sha512-pW7uC1l4mBZ8ugbiZrcIsiIvVx1UmTfw7UkC3Um2tmfUq9Bhk8IiyEIPl6F8agHgjzku6j0xQEZbfA5uSgSaCw==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/styled-jsx/-/styled-jsx-5.1.1.tgz} id: registry.npmmirror.com/styled-jsx/5.1.1 name: styled-jsx @@ -11674,6 +11690,7 @@ packages: babel-plugin-macros: optional: true dependencies: + '@babel/core': registry.npmmirror.com/@babel/core@7.22.5 client-only: registry.npmmirror.com/client-only@0.0.1 react: registry.npmmirror.com/react@18.2.0 dev: false @@ -12117,7 +12134,6 @@ packages: browserslist: registry.npmmirror.com/browserslist@4.21.7 escalade: registry.npmmirror.com/escalade@3.1.1 picocolors: registry.npmmirror.com/picocolors@1.0.0 - dev: true registry.npmmirror.com/uri-js@4.4.1: resolution: {integrity: sha512-7rKUyy33Q1yc98pQ1DAmLtwX109F7TIfWlW1Ydo8Wl1ii1SeHieeh0HHfPeL2fMXK6z0s8ecKs9frCuLJvndBg==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/uri-js/-/uri-js-4.4.1.tgz} @@ -12480,7 +12496,6 @@ packages: resolution: {integrity: sha512-a4UGQaWPH59mOXUYnAG2ewncQS4i4F43Tv3JoAM+s2VDAmS9NsK8GpDMLrCHPksFT7h3K6TOoUNn2pb7RoXx4g==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/yallist/-/yallist-3.1.1.tgz} name: yallist version: 3.1.1 - dev: true registry.npmmirror.com/yallist@4.0.0: resolution: {integrity: sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/yallist/-/yallist-4.0.0.tgz} @@ -12533,7 +12548,3 @@ packages: name: zwitch version: 2.0.4 dev: false - -settings: - autoInstallPeers: true - excludeLinksFromLockfile: false diff --git a/client/src/api/plugins/kb.ts b/client/src/api/plugins/kb.ts index e5059fb7038..f92e741ec28 100644 --- a/client/src/api/plugins/kb.ts +++ b/client/src/api/plugins/kb.ts @@ -13,6 +13,8 @@ import { Props as UpdateDataProps } from '@/pages/api/openapi/kb/updateData'; import type { KbUpdateParams, CreateKbParams, GetKbDataListProps } from '../request/kb'; import { QuoteItemType } from '@/types/chat'; import { KbTypeEnum } from '@/constants/kb'; +import { getToken } from '@/utils/user'; +import download from 'downloadjs'; /* knowledge base */ export const getKbList = (data: { parentId?: string; type?: `${KbTypeEnum}` }) => @@ -35,12 +37,23 @@ export const getKbDataList = (data: GetKbDataListProps) => POST(`/plugins/kb/data/getDataList`, data); /** - * 获取导出数据(不分页) + * export and download data */ -export const getExportDataList = (data: { kbId: string }) => - GET<[string, string, string][]>(`/plugins/kb/data/exportModelData`, data, { - timeout: 600000 - }); +export const exportDataset = (data: { kbId: string }) => + fetch(`/api/plugins/kb/data/exportAll?kbId=${data.kbId}`, { + method: 'GET', + headers: { + token: getToken() + } + }) + .then(async (res) => { + if (!res.ok) { + const data = await res.json(); + throw new Error(data?.message || 'Export failed'); + } + return res.blob(); + }) + .then((blob) => download(blob, 'dataset.csv', 'text/csv')); /** * 获取模型正在拆分数据的数量 diff --git a/client/src/components/ChatBox/index.tsx b/client/src/components/ChatBox/index.tsx index 0c7498e488b..a766a377f91 100644 --- a/client/src/components/ChatBox/index.tsx +++ b/client/src/components/ChatBox/index.tsx @@ -452,29 +452,22 @@ const ChatBox = ( border: theme.borders.base, mr: 3 }; - const controlContainerStyle = useCallback((status: ChatSiteItemType['status']) => { - return { - className: 'control', - color: 'myGray.400', - display: - status === 'finish' - ? feedbackType === FeedbackTypeEnum.admin - ? 'flex' - : ['flex', 'none'] - : 'none', - pl: 1, - mt: 2 - }; - }, []); + const controlContainerStyle = { + className: 'control', + color: 'myGray.400', + display: 'flex', + pl: 1, + mt: 2 + }; const MessageCardStyle: BoxProps = { px: 4, py: 3, borderRadius: '0 8px 8px 8px', - boxShadow: '0 0 8px rgba(0,0,0,0.15)' + boxShadow: '0 0 8px rgba(0,0,0,0.15)', + display: 'inline-block', + maxW: ['calc(100% - 25px)', 'calc(100% - 40px)'] }; - const messageCardMaxW = ['calc(100% - 25px)', 'calc(100% - 40px)']; - const showEmpty = useMemo( () => feConfigs?.show_emptyChat && @@ -542,84 +535,80 @@ const ChatBox = ( {showEmpty && } {!!welcomeText && ( - + {/* avatar */} {/* message */} - - - - + + + + + + )} {/* variable input */} {!!variableModules?.length && ( - + {/* avatar */} {/* message */} - - {variableModules.map((item) => ( - - {item.label} - {item.type === VariableInputEnum.input && ( - - )} - {item.type === VariableInputEnum.select && ( - ({ - label: item.value, - value: item.value - }))} - {...register(item.key, { - required: item.required - })} - value={getValues(item.key)} - onchange={(e) => { - setValue(item.key, e); - setRefresh(!refresh); - }} - /> - )} - - ))} - {!variableIsFinish && ( - - )} - - + + + {variableModules.map((item) => ( + + {item.label} + {item.type === VariableInputEnum.input && ( + + )} + {item.type === VariableInputEnum.select && ( + ({ + label: item.value, + value: item.value + }))} + {...register(item.key, { + required: item.required + })} + value={getValues(item.key)} + onchange={(e) => { + setValue(item.key, e); + setRefresh(!refresh); + }} + /> + )} + + ))} + {!variableIsFinish && ( + + )} + + + )} {/* chat history */} {chatHistory.map((item, index) => ( - - + - + - + )} - + )} - + ))} diff --git a/client/src/constants/user.ts b/client/src/constants/user.ts index 1eb5ba79735..2cb6ff4fe61 100644 --- a/client/src/constants/user.ts +++ b/client/src/constants/user.ts @@ -14,7 +14,7 @@ export enum PageTypeEnum { } export const BillSourceMap: Record<`${BillSourceEnum}`, string> = { - [BillSourceEnum.fastgpt]: 'FastGPT 平台', + [BillSourceEnum.fastgpt]: '在线使用', [BillSourceEnum.api]: 'Api', [BillSourceEnum.shareLink]: '免登录链接' }; diff --git a/client/src/pages/account/components/Info.tsx b/client/src/pages/account/components/Info.tsx index ae97076b7e2..88a551ddc4f 100644 --- a/client/src/pages/account/components/Info.tsx +++ b/client/src/pages/account/components/Info.tsx @@ -251,7 +251,7 @@ const UserInfo = () => { )} - {feConfigs?.show_userDetail && ( + {feConfigs?.show_openai_account && ( <> diff --git a/client/src/pages/account/components/PayModal.tsx b/client/src/pages/account/components/PayModal.tsx index f39192999fa..9579731fbb4 100644 --- a/client/src/pages/account/components/PayModal.tsx +++ b/client/src/pages/account/components/PayModal.tsx @@ -6,8 +6,10 @@ import { useQuery } from '@tanstack/react-query'; import { useRouter } from 'next/router'; import { getErrText } from '@/utils/tools'; import { useTranslation } from 'react-i18next'; +import { formatPrice } from '@/utils/user'; import Markdown from '@/components/Markdown'; import MyModal from '@/components/MyModal'; +import { vectorModelList, chatModelList, qaModel } from '@/store/static'; const PayModal = ({ onClose }: { onClose: () => void }) => { const router = useRouter(); @@ -69,6 +71,7 @@ const PayModal = ({ onClose }: { onClose: () => void }) => { onClose(); }} title={t('user.Pay')} + isCentered showCloseBtn={!payId} > @@ -100,11 +103,13 @@ const PayModal = ({ onClose }: { onClose: () => void }) => { source={` | 计费项 | 价格: 元/ 1K tokens(包含上下文)| | --- | --- | -| 知识库 - 索引 | 0.002 | -| FastAI4k - 对话 | 0.015 | -| FastAI16k - 对话 | 0.03 | -| FastAI-Plus - 对话 | 0.45 | -| 文件QA拆分 | 0.03 |`} +${vectorModelList + .map((item) => `| 索引-${item.name} | ${formatPrice(item.price, 1000)} |`) + .join('\n')} +${chatModelList + .map((item) => `| 对话-${item.name} | ${formatPrice(item.price, 1000)} |`) + .join('\n')} +| 文件QA拆分 | ${formatPrice(qaModel.price, 1000)} |`} /> )} diff --git a/client/src/pages/account/index.tsx b/client/src/pages/account/index.tsx index d15bafecc2f..5ba681e8b46 100644 --- a/client/src/pages/account/index.tsx +++ b/client/src/pages/account/index.tsx @@ -31,7 +31,7 @@ enum TabEnum { const Account = ({ currentTab }: { currentTab: `${TabEnum}` }) => { const { t } = useTranslation(); - const tabList = useRef([ + const tabList = [ { icon: 'meLight', label: t('user.Personal Information'), @@ -67,7 +67,7 @@ const Account = ({ currentTab }: { currentTab: `${TabEnum}` }) => { label: t('user.Sign Out'), id: TabEnum.loginout } - ]); + ]; const { openConfirm, ConfirmModal } = useConfirm({ content: '确认退出登录?' @@ -115,7 +115,7 @@ const Account = ({ currentTab }: { currentTab: `${TabEnum}` }) => { mx={'auto'} mt={2} w={'100%'} - list={tabList.current} + list={tabList} activeId={currentTab} onChange={setCurrentTab} /> @@ -125,7 +125,7 @@ const Account = ({ currentTab }: { currentTab: `${TabEnum}` }) => { ({ + list={tabList.map((item) => ({ id: item.id, label: item.label }))} diff --git a/client/src/pages/api/admin/initv442.ts b/client/src/pages/api/admin/initv442.ts new file mode 100644 index 00000000000..61def2ccc17 --- /dev/null +++ b/client/src/pages/api/admin/initv442.ts @@ -0,0 +1,27 @@ +import type { NextApiRequest, NextApiResponse } from 'next'; +import { jsonRes } from '@/service/response'; +import { authUser } from '@/service/utils/auth'; +import { connectToDatabase, Bill } from '@/service/mongo'; + +export default async function handler(req: NextApiRequest, res: NextApiResponse) { + try { + await connectToDatabase(); + await authUser({ req, authRoot: true }); + + try { + await Bill.collection.dropIndex('time_1'); + } catch (error) {} + try { + await Bill.collection.createIndex({ time: 1 }, { expireAfterSeconds: 90 * 24 * 60 * 60 }); + } catch (error) {} + + jsonRes(res, { + data: {} + }); + } catch (error) { + jsonRes(res, { + code: 500, + error + }); + } +} diff --git a/client/src/pages/api/core/dataset/file/delById.ts b/client/src/pages/api/core/dataset/file/delById.ts index a4292dc9f6c..1fa5f2e3940 100644 --- a/client/src/pages/api/core/dataset/file/delById.ts +++ b/client/src/pages/api/core/dataset/file/delById.ts @@ -1,6 +1,6 @@ import type { NextApiRequest, NextApiResponse } from 'next'; import { jsonRes } from '@/service/response'; -import { connectToDatabase } from '@/service/mongo'; +import { connectToDatabase, TrainingData } from '@/service/mongo'; import { authUser } from '@/service/utils/auth'; import { GridFSStorage } from '@/service/lib/gridfs'; import { PgClient } from '@/service/pg'; @@ -21,6 +21,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse< // 凭证校验 const { userId } = await authUser({ req, authToken: true }); + // other data. Delete only vector data if (fileId === OtherFileId) { await PgClient.delete(PgDatasetTableName, { where: [ @@ -31,6 +32,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse< ] }); } else { + // auth file const gridFs = new GridFSStorage('dataset', userId); const bucket = gridFs.GridFSBucket(); @@ -40,6 +42,11 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse< await PgClient.delete(PgDatasetTableName, { where: [['user_id', userId], 'AND', ['kb_id', kbId], 'AND', ['file_id', fileId]] }); + // delete all training data + await TrainingData.deleteMany({ + userId, + file_id: fileId + }); // delete file await bucket.delete(new Types.ObjectId(fileId)); diff --git a/client/src/pages/api/openapi/postKey.ts b/client/src/pages/api/openapi/postKey.ts index 53f30fa5992..1f3a9efee56 100644 --- a/client/src/pages/api/openapi/postKey.ts +++ b/client/src/pages/api/openapi/postKey.ts @@ -18,7 +18,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) throw new Error('最多 10 组 API 秘钥'); } - const apiKey = `fastgpt-${nanoid()}`; + const apiKey = `${global.systemEnv?.openapiPrefix || 'fastgpt'}-${nanoid()}`; await OpenApi.create({ userId, diff --git a/client/src/pages/api/openapi/v1/chat/completions.ts b/client/src/pages/api/openapi/v1/chat/completions.ts index df1c03525ca..c56a7b44fae 100644 --- a/client/src/pages/api/openapi/v1/chat/completions.ts +++ b/client/src/pages/api/openapi/v1/chat/completions.ts @@ -116,7 +116,7 @@ export default withNextCors(async function handler(req: NextApiRequest, res: Nex appId, userId }), - getChatHistory({ chatId, userId }) + getChatHistory({ chatId, appId, userId }) ]); const isOwner = !shareId && userId === String(app.userId); diff --git a/client/src/pages/api/openapi/v1/chat/getHistory.ts b/client/src/pages/api/openapi/v1/chat/getHistory.ts index f44097346ba..0c653f85002 100644 --- a/client/src/pages/api/openapi/v1/chat/getHistory.ts +++ b/client/src/pages/api/openapi/v1/chat/getHistory.ts @@ -7,6 +7,7 @@ import { Types } from 'mongoose'; import type { ChatItemType } from '@/types/chat'; export type Props = { + appId?: string; chatId?: string; limit?: number; }; @@ -36,9 +37,10 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) export async function getChatHistory({ chatId, userId, + appId, limit = 30 }: Props & { userId: string }): Promise { - if (!chatId) { + if (!chatId || !appId) { return { history: [] }; } @@ -46,6 +48,7 @@ export async function getChatHistory({ { $match: { chatId, + appId: new Types.ObjectId(appId), userId: new Types.ObjectId(userId) } }, diff --git a/client/src/pages/api/plugins/kb/data/exportModelData.ts b/client/src/pages/api/plugins/kb/data/exportAll.ts similarity index 52% rename from client/src/pages/api/plugins/kb/data/exportModelData.ts rename to client/src/pages/api/plugins/kb/data/exportAll.ts index a6e4f8b4e00..326d96be868 100644 --- a/client/src/pages/api/plugins/kb/data/exportModelData.ts +++ b/client/src/pages/api/plugins/kb/data/exportAll.ts @@ -2,9 +2,10 @@ import type { NextApiRequest, NextApiResponse } from 'next'; import { jsonRes } from '@/service/response'; import { connectToDatabase, User } from '@/service/mongo'; import { authUser } from '@/service/utils/auth'; -import { PgClient } from '@/service/pg'; import { PgDatasetTableName } from '@/constants/plugin'; import { findAllChildrenIds } from '../delete'; +import QueryStream from 'pg-query-stream'; +import Papa from 'papaparse'; export default async function handler(req: NextApiRequest, res: NextApiResponse) { try { @@ -12,7 +13,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse< kbId: string; }; - if (!kbId) { + if (!kbId || !global.pgClient) { throw new Error('缺少参数'); } @@ -22,7 +23,6 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse< const { userId } = await authUser({ req, authToken: true }); const exportIds = [kbId, ...(await findAllChildrenIds(kbId))]; - console.log(exportIds); const thirtyMinutesAgo = new Date( Date.now() - (global.feConfigs?.limit?.exportLimitMinutes || 0) * 60 * 1000 @@ -45,37 +45,50 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse< throw new Error(`上次导出未到 ${minutes},每 ${minutes}仅可导出一次。`); } - const where: any = [ - ['user_id', userId], - 'AND', - `kb_id IN (${exportIds.map((id) => `'${id}'`).join(',')})` - ]; - // 从 pg 中获取所有数据 - const pgData = await PgClient.select<{ q: string; a: string; source: string }>( - PgDatasetTableName, - { - where, - fields: ['q', 'a', 'source'], - order: [{ field: 'id', mode: 'DESC' }], - limit: 1000000 + // connect pg + global.pgClient.connect((err, client, done) => { + if (err) { + console.error(err); + res.end('Error connecting to database'); + return; } - ); + // create pg select stream + const query = new QueryStream( + `SELECT q, a, source FROM ${PgDatasetTableName} where user_id='${userId}' AND kb_id IN (${exportIds + .map((id) => `'${id}'`) + .join(',')})` + ); + const stream = client.query(query); - const data: [string, string, string][] = pgData.rows.map((item) => [ - item.q.replace(/\n/g, '\\n'), - item.a.replace(/\n/g, '\\n'), - item.source - ]); + res.setHeader('Content-Disposition', 'attachment; filename=dataset.csv'); + res.setHeader('Content-Type', 'text/csv'); - // update export time - await User.findByIdAndUpdate(userId, { - 'limit.exportKbTime': new Date() - }); + res.write('index,content,source'); - jsonRes(res, { - data + // parse data every row + stream.on('data', (row: { q: string; a: string; source?: string }) => { + const csv = Papa.unparse([row], { header: false }); + res.write(`\n${csv}`); + }); + stream.on('end', async () => { + try { + // update export time + await User.findByIdAndUpdate(userId, { + 'limit.exportKbTime': new Date() + }); + } catch (error) {} + + // close response + done(); + res.end(); + }); + stream.on('error', (err) => { + done(err); + res.end('Error exporting data'); + }); }); } catch (err) { + res.status(500); jsonRes(res, { code: 500, error: err diff --git a/client/src/pages/app/detail/components/API.tsx b/client/src/pages/app/detail/components/API.tsx index 0bc0d161fc0..2f1a966af6b 100644 --- a/client/src/pages/app/detail/components/API.tsx +++ b/client/src/pages/app/detail/components/API.tsx @@ -4,6 +4,7 @@ import { useCopyData } from '@/utils/tools'; import dynamic from 'next/dynamic'; import MyIcon from '@/components/Icon'; import { useGlobalStore } from '@/store/global'; +import { feConfigs } from '@/store/static'; const APIKeyModal = dynamic(() => import('@/components/APIKeyModal'), { ssr: false @@ -77,7 +78,10 @@ const API = ({ appId }: { appId: string }) => { width: '100%', height: '100%' }} - src="https://kjqvjse66l.feishu.cn/docx/DmLedTWtUoNGX8xui9ocdUEjnNh" + src={ + feConfigs?.openAPIUrl || + 'https://kjqvjse66l.feishu.cn/docx/DmLedTWtUoNGX8xui9ocdUEjnNh' + } frameBorder="0" onLoad={() => setIsLoaded(true)} onError={() => setIsLoaded(true)} diff --git a/client/src/pages/app/detail/components/KBSelectModal.tsx b/client/src/pages/app/detail/components/KBSelectModal.tsx index 2e0a223e2b8..8334d9a0daf 100644 --- a/client/src/pages/app/detail/components/KBSelectModal.tsx +++ b/client/src/pages/app/detail/components/KBSelectModal.tsx @@ -27,6 +27,7 @@ import { KbTypeEnum } from '@/constants/kb'; import { useTranslation } from 'react-i18next'; import { useQuery } from '@tanstack/react-query'; import { useDatasetStore } from '@/store/dataset'; +import { feConfigs } from '@/store/static'; export type KbParamsType = { searchSimilarity: number; @@ -345,9 +346,7 @@ export const KbParamsModal = ({ diff --git a/client/src/pages/app/detail/index.tsx b/client/src/pages/app/detail/index.tsx index 56909a8396f..b928ed0ae03 100644 --- a/client/src/pages/app/detail/index.tsx +++ b/client/src/pages/app/detail/index.tsx @@ -35,7 +35,8 @@ enum TabEnum { 'adEdit' = 'adEdit', 'outLink' = 'outLink', 'logs' = 'logs', - 'API' = 'API' + 'API' = 'API', + 'startChat' = 'startChat' } const AppDetail = ({ currentTab }: { currentTab: `${TabEnum}` }) => { @@ -64,7 +65,7 @@ const AppDetail = ({ currentTab }: { currentTab: `${TabEnum}` }) => { { label: '外部使用', id: TabEnum.outLink, icon: 'shareLight' }, { label: 'API访问', id: TabEnum.API, icon: 'apiLight' }, { label: '对话日志', id: TabEnum.logs, icon: 'logsLight' }, - { label: '立即对话', id: 'startChat', icon: 'chat' } + { label: '立即对话', id: TabEnum.startChat, icon: 'chat' } ], [] ); diff --git a/client/src/pages/chat/components/ChatHeader.tsx b/client/src/pages/chat/components/ChatHeader.tsx index daa5d8906e7..07852dbe592 100644 --- a/client/src/pages/chat/components/ChatHeader.tsx +++ b/client/src/pages/chat/components/ChatHeader.tsx @@ -49,7 +49,7 @@ const ChatHeader = ({ {history.length === 0 ? '新的对话' : `${history.length}条记录`} - {!!chatModels && ( + {!!chatModels && chatModels.length > 0 && ( {chatModels.join(',')} diff --git a/client/src/pages/kb/detail/components/Import/Csv.tsx b/client/src/pages/kb/detail/components/Import/Csv.tsx index c0aef2bfea2..ddb6f4f902d 100644 --- a/client/src/pages/kb/detail/components/Import/Csv.tsx +++ b/client/src/pages/kb/detail/components/Import/Csv.tsx @@ -217,7 +217,7 @@ const CsvImport = ({ kbId }: { kbId: string }) => { /> - {`q: ${item.q}\na: ${item.a}`} + {`${item.q}\n${item.a}`} )) diff --git a/client/src/pages/kb/detail/components/Import/FileSelect.tsx b/client/src/pages/kb/detail/components/Import/FileSelect.tsx index c46ceeb3b3d..5fbe2b2184a 100644 --- a/client/src/pages/kb/detail/components/Import/FileSelect.tsx +++ b/client/src/pages/kb/detail/components/Import/FileSelect.tsx @@ -25,7 +25,7 @@ const UrlFetchModal = dynamic(() => import('./UrlFetchModal')); const CreateFileModal = dynamic(() => import('./CreateFileModal')); const nanoid = customAlphabet('abcdefghijklmnopqrstuvwxyz1234567890', 12); -const csvTemplate = `question,answer\n"什么是 laf","laf 是一个云函数开发平台……"\n"什么是 sealos","Sealos 是以 kubernetes 为内核的云操作系统发行版,可以……"`; +const csvTemplate = `index,content,source\n"被索引的内容","对应的答案。CSV 中请注意内容不能包含双引号,双引号是列分割符号","来源,可选。"\n"什么是 laf","laf 是一个云函数开发平台……",""\n"什么是 sealos","Sealos 是以 kubernetes 为内核的云操作系统发行版,可以……",""`; export type FileItemType = { id: string; @@ -149,8 +149,8 @@ const FileSelect = ({ /* csv file */ if (extension === 'csv') { const { header, data } = await readCsvContent(file); - if (header[0] !== 'question' || header[1] !== 'answer') { - throw new Error('csv 文件格式有误,请确保 question 和 answer 两列'); + if (header[0] !== 'index' || header[1] !== 'content') { + throw new Error('csv 文件格式有误,请确保 index 和 content 两列'); } const fileItem: FileItemType = { id: filesId[0], @@ -158,12 +158,14 @@ const FileSelect = ({ icon, tokens: 0, text: '', - chunks: data.map((item) => ({ - q: item[0], - a: item[1], - source: item[2] || file.name, - file_id: filesId[0] - })) + chunks: data + .filter((item) => item[0]) + .map((item) => ({ + q: item[0] || '', + a: item[1] || '', + source: item[2] || file.name || '', + file_id: filesId[0] + })) }; chunkFiles.unshift(fileItem); diff --git a/client/src/pages/kb/list/index.tsx b/client/src/pages/kb/list/index.tsx index 49f63ad2e1f..fffe55fc320 100644 --- a/client/src/pages/kb/list/index.tsx +++ b/client/src/pages/kb/list/index.tsx @@ -15,7 +15,7 @@ import PageContainer from '@/components/PageContainer'; import { useConfirm } from '@/hooks/useConfirm'; import { AddIcon } from '@chakra-ui/icons'; import { useQuery } from '@tanstack/react-query'; -import { delKbById, getExportDataList, getKbPaths, putKbById } from '@/api/plugins/kb'; +import { delKbById, exportDataset, getKbPaths, putKbById } from '@/api/plugins/kb'; import { useTranslation } from 'react-i18next'; import Avatar from '@/components/Avatar'; import MyIcon from '@/components/Icon'; @@ -27,8 +27,6 @@ import MyMenu from '@/components/MyMenu'; import { useRequest } from '@/hooks/useRequest'; import { useGlobalStore } from '@/store/global'; import { useEditTitle } from '@/hooks/useEditTitle'; -import Papa from 'papaparse'; -import { fileDownload } from '@/utils/file'; import { feConfigs } from '@/store/static'; const CreateModal = dynamic(() => import('./component/CreateModal'), { ssr: false }); @@ -90,19 +88,7 @@ const Kb = () => { const { mutate: onclickExport } = useRequest({ mutationFn: (kbId: string) => { setLoading(true); - return getExportDataList({ kbId }); - }, - onSuccess(res) { - const text = Papa.unparse({ - fields: ['question', 'answer', 'source'], - data: res - }); - - fileDownload({ - text, - type: 'text/csv', - filename: 'dataset.csv' - }); + return exportDataset({ kbId }); }, onSettled() { setLoading(false); diff --git a/client/src/pages/login/components/RegisterForm.tsx b/client/src/pages/login/components/RegisterForm.tsx index 6caf616f7ed..aca2e5e7dc9 100644 --- a/client/src/pages/login/components/RegisterForm.tsx +++ b/client/src/pages/login/components/RegisterForm.tsx @@ -65,13 +65,15 @@ const RegisterForm = ({ setPageType, loginSuccess }: Props) => { status: 'success' }); // auto register template app - appTemplates.forEach((template) => { - postCreateApp({ - avatar: template.avatar, - name: template.name, - modules: template.modules + setTimeout(() => { + appTemplates.forEach((template) => { + postCreateApp({ + avatar: template.avatar, + name: template.name, + modules: template.modules + }); }); - }); + }, 100); } catch (error: any) { toast({ title: error.message || '注册异常', diff --git a/client/src/pages/login/index.tsx b/client/src/pages/login/index.tsx index 57113903c5b..3d106d5a65b 100644 --- a/client/src/pages/login/index.tsx +++ b/client/src/pages/login/index.tsx @@ -36,7 +36,7 @@ const Login = () => { setToken(res.token); setTimeout(() => { router.push(lastRoute ? decodeURIComponent(lastRoute) : '/app/list'); - }, 100); + }, 300); }, [lastRoute, router, setLastChatId, setLastChatAppId, setUserInfo] ); diff --git a/client/src/service/models/bill.ts b/client/src/service/models/bill.ts index 2f0731bbc52..e22745034dc 100644 --- a/client/src/service/models/bill.ts +++ b/client/src/service/models/bill.ts @@ -55,7 +55,7 @@ const BillSchema = new Schema({ try { BillSchema.index({ userId: 1 }); - BillSchema.index({ time: 1 }, { expireAfterSeconds: 90 * 24 * 60 }); + BillSchema.index({ time: 1 }, { expireAfterSeconds: 90 * 24 * 60 * 60 }); } catch (error) { console.log(error); } diff --git a/client/src/types/index.d.ts b/client/src/types/index.d.ts index 3042d2e0152..5e2d2bfc3f4 100644 --- a/client/src/types/index.d.ts +++ b/client/src/types/index.d.ts @@ -23,9 +23,10 @@ export type FeConfigsType = { show_contact?: boolean; show_git?: boolean; show_doc?: boolean; + show_openai_account?: boolean; + openAPIUrl?: string; systemTitle?: string; authorText?: string; - beianText?: string; googleClientVerKey?: string; oauth?: { github?: string; @@ -38,6 +39,7 @@ export type FeConfigsType = { }; export type SystemEnvType = { pluginBaseUrl?: string; + openapiPrefix?: string; vectorMaxProcess: number; qaMaxProcess: number; pgIvfflatProbe: number;