Skip to content

Commit

Permalink
v4.6-3 (#463)
Browse files Browse the repository at this point in the history
  • Loading branch information
c121914yu authored Nov 10, 2023
1 parent 0a0fe31 commit d91551e
Show file tree
Hide file tree
Showing 17 changed files with 257 additions and 26 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"format-doc": "zhlint --dir ./docSite *.md --fix"
},
"devDependencies": {
"@types/multer": "^1.4.10",
"husky": "^8.0.3",
"i18next": "^22.5.1",
"lint-staged": "^13.2.1",
Expand All @@ -24,6 +25,7 @@
"node": ">=18.0.0"
},
"dependencies": {
"multer": "1.4.5-lts.1",
"openai": "4.16.1"
}
}
71 changes: 71 additions & 0 deletions packages/service/common/file/upload/multer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import type { NextApiRequest, NextApiResponse } from 'next';
import { customAlphabet } from 'nanoid';
import multer from 'multer';
import path from 'path';
import { BucketNameEnum } from '@fastgpt/global/common/file/constants';

const nanoid = customAlphabet('1234567890abcdef', 12);

type FileType = {
fieldname: string;
originalname: string;
encoding: string;
mimetype: string;
filename: string;
path: string;
size: number;
};

export function getUploadModel({ maxSize = 500 }: { maxSize?: number }) {
maxSize *= 1024 * 1024;
class UploadModel {
uploader = multer({
limits: {
fieldSize: maxSize
},
preservePath: true,
storage: multer.diskStorage({
filename: (_req, file, cb) => {
const { ext } = path.parse(decodeURIComponent(file.originalname));
cb(null, nanoid() + ext);
}
})
}).any();

async doUpload(req: NextApiRequest, res: NextApiResponse) {
return new Promise<{
files: FileType[];
metadata: Record<string, any>;
bucketName?: `${BucketNameEnum}`;
}>((resolve, reject) => {
// @ts-ignore
this.uploader(req, res, (error) => {
if (error) {
return reject(error);
}

resolve({
...req.body,
files:
// @ts-ignore
req.files?.map((file) => ({
...file,
originalname: decodeURIComponent(file.originalname)
})) || [],
metadata: (() => {
if (!req.body?.metadata) return {};
try {
return JSON.parse(req.body.metadata);
} catch (error) {
console.log(error);
return {};
}
})()
});
});
});
}
}

return new UploadModel();
}
16 changes: 11 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion projects/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"@types/jsdom": "^21.1.1",
"@types/jsonwebtoken": "^9.0.3",
"@types/lodash": "^4.14.191",
"@types/multer": "^1.4.7",
"@types/multer": "^1.4.10",
"@types/node": "^20.8.5",
"@types/papaparse": "^5.3.7",
"@types/react": "18.0.28",
Expand Down
7 changes: 6 additions & 1 deletion projects/app/public/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,9 @@
},
"input": {
"Repeat Value": "Repeat Value"
},
"speech": {
"error tip": "Speech Failed"
}
},
"core": {
Expand All @@ -226,8 +229,10 @@
},
"chat": {
"Audio Speech Error": "Audio Speech Error",
"Record": "Speech",
"Restart": "Restart",
"Send Message": "Send Message"
"Send Message": "Send Message",
"Stop Speak": "Stop Speak"
},
"dataset": {
"Choose Dataset": "Choose Dataset",
Expand Down
7 changes: 6 additions & 1 deletion projects/app/public/locales/zh/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,9 @@
},
"input": {
"Repeat Value": "有重复的值"
},
"speech": {
"error tip": "语音转文字失败"
}
},
"core": {
Expand All @@ -226,8 +229,10 @@
},
"chat": {
"Audio Speech Error": "语音播报异常",
"Record": "语音输入",
"Restart": "重开对话",
"Send Message": "发送"
"Send Message": "发送",
"Stop Speak": "停止录音"
},
"dataset": {
"Choose Dataset": "关联知识库",
Expand Down
30 changes: 21 additions & 9 deletions projects/app/src/components/ChatBox/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ import styles from './index.module.scss';
import { postQuestionGuide } from '@/web/core/ai/api';
import { splitGuideModule } from '@/global/core/app/modules/utils';
import { AppTTSConfigType } from '@/types/app';
import { useSpeech } from '@/web/common/hooks/useSpeech';

const nanoid = customAlphabet('abcdefghijklmnopqrstuvwxyz1234567890', 24);

Expand Down Expand Up @@ -149,6 +150,8 @@ const ChatBox = (
const [adminMarkData, setAdminMarkData] = useState<AdminMarkType & { chatItemId: string }>();
const [questionGuides, setQuestionGuide] = useState<string[]>([]);

const { isSpeaking, startSpeak, stopSpeak } = useSpeech();

const isChatting = useMemo(
() =>
chatHistory[chatHistory.length - 1] &&
Expand Down Expand Up @@ -857,8 +860,22 @@ const ChatBox = (
right={['12px', '14px']}
bottom={['15px', '13px']}
borderRadius={'md'}
bg={TextareaDom.current?.value ? 'myBlue.600' : ''}
// bg={TextareaDom.current?.value ? 'myBlue.600' : ''}
cursor={'pointer'}
lineHeight={1}
onClick={() => {
if (isChatting) {
return chatController.current?.abort('stop');
}
if (TextareaDom.current?.value) {
return handleSubmit((data) => sendPrompt(data, TextareaDom.current?.value))();
}
// speech
// if (isSpeaking) {
// return stopSpeak();
// }
// startSpeak();
}}
>
{isChatting ? (
<MyIcon
Expand All @@ -868,19 +885,14 @@ const ChatBox = (
cursor={'pointer'}
name={'stop'}
color={'gray.500'}
onClick={() => chatController.current?.abort('stop')}
/>
) : (
<MyTooltip label={t('core.chat.Send Message')}>
<MyIcon
name={'core/chat/sendFill'}
width={'16px'}
height={'16px'}
cursor={'pointer'}
color={TextareaDom.current?.value ? 'white' : 'myBlue.600'}
onClick={() => {
handleSubmit((data) => sendPrompt(data, TextareaDom.current?.value))();
}}
width={['16px', '22px']}
height={['16px', '22px']}
color={TextareaDom.current?.value ? 'myBlue.600' : 'myGray.400'}
/>
</MyTooltip>
)}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion projects/app/src/components/Icon/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ const iconPaths = {
'support/permission/publicLight': () => import('./icons/support/permission/publicLight.svg'),
'core/app/ttsFill': () => import('./icons/core/app/ttsFill.svg'),
'common/playLight': () => import('./icons/common/playLight.svg'),
'core/chat/sendFill': () => import('./icons/core/chat/sendFill.svg')
'core/chat/sendFill': () => import('./icons/core/chat/sendFill.svg'),
'core/chat/recordFill': () => import('./icons/core/chat/recordFill.svg'),
'core/chat/stopSpeechFill': () => import('./icons/core/chat/stopSpeechFill.svg')
};

export type IconName = keyof typeof iconPaths;
Expand Down
2 changes: 1 addition & 1 deletion projects/app/src/components/Layout/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const Layout = ({ children }: { children: JSX.Element }) => {
}, [loadGitStar, setScreenWidth]);

const { data: unread = 0 } = useQuery(['getUnreadCount'], getUnreadCount, {
enabled: !!userInfo && feConfigs.isPlus,
enabled: !!userInfo && !!feConfigs.isPlus,
refetchInterval: 10000
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const TagTextarea = ({ defaultValues, onUpdate, ...props }: Props) => {
return;
}
if (tags.includes(value)) {
toast({
return toast({
status: 'warning',
title: t('common.input.Repeat Value')
});
Expand Down
4 changes: 2 additions & 2 deletions projects/app/src/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,11 @@ function App({ Component, pageProps }: AppProps) {
setLastRoute(router.asPath);
};
}, [router.asPath]);
``;

return (
<>
<Head>
<title>{feConfigs?.systemTitle || 'AI'}</title>
<title>{feConfigs?.systemTitle || 'FastGPT'}</title>
<meta
name="description"
content="FastGPT is a knowledge-based question answering system built on the LLM. It offers out-of-the-box data processing and model invocation capabilities. Moreover, it allows for workflow orchestration through Flow visualization, thereby enabling complex question and answer scenarios!"
Expand Down
3 changes: 2 additions & 1 deletion projects/app/src/pages/api/common/file/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ class UploadModel {
}

resolve({
...req.body,
files:
// @ts-ignore
req.files?.map((file) => ({
...file,
originalname: decodeURIComponent(file.originalname)
})) || [],
bucketName: req.body.bucketName,
metadata: (() => {
if (!req.body?.metadata) return {};
try {
Expand All @@ -80,6 +80,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
try {
await connectToDatabase();
const { userId, teamId, tmbId } = await authCert({ req, authToken: true });
console.log(req.body);

const { files, bucketName, metadata } = await upload.doUpload(req, res);

Expand Down
6 changes: 3 additions & 3 deletions projects/app/src/pages/api/core/dataset/data/exportAll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { MongoUser } from '@fastgpt/service/support/user/schema';
import { PgDatasetTableName } from '@fastgpt/global/core/dataset/constant';
import { findAllChildrenIds } from '../delete';
import QueryStream from 'pg-query-stream';
import { PgClient, Pg } from '@fastgpt/service/common/pg';
import { PgClient } from '@fastgpt/service/common/pg';
import { addLog } from '@fastgpt/service/common/mongo/controller';
import { responseWriteController } from '@fastgpt/service/common/response';
import { authDataset } from '@fastgpt/service/support/permission/auth/dataset';
Expand All @@ -17,7 +17,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
datasetId: string;
};

if (!datasetId || !Pg) {
if (!datasetId || !global.pgClient) {
throw new Error('缺少参数');
}

Expand Down Expand Up @@ -61,7 +61,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
}

// connect pg
Pg.connect((err, client, done) => {
global.pgClient.connect((err, client, done) => {
if (err) {
console.error(err);
res.end('Error connecting to database');
Expand Down
Loading

0 comments on commit d91551e

Please sign in to comment.