mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-27 16:33:49 +00:00
feat: 错误提示
This commit is contained in:
@@ -50,13 +50,13 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||
const formatPrompts: ChatCompletionRequestMessage[] = filterPrompts.map(
|
||||
(item: ChatItemType) => ({
|
||||
role: map[item.obj],
|
||||
content: item.value.replace(/\n/g, ' ')
|
||||
content: item.value
|
||||
})
|
||||
);
|
||||
// 第一句话,强调代码类型
|
||||
formatPrompts.unshift({
|
||||
role: ChatCompletionRequestMessageRoleEnum.System,
|
||||
content: '如果你想返回代码,请务必声明代码的类型!'
|
||||
content: '如果你想返回代码,请务必声明代码的类型!并且在代码块前加一个换行符。'
|
||||
});
|
||||
// 获取 chatAPI
|
||||
const chatAPI = getOpenAIApi(userApiKey);
|
||||
@@ -100,7 +100,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||
}
|
||||
try {
|
||||
const json = JSON.parse(data);
|
||||
const content: string = json.choices[0].delta.content || '';
|
||||
const content: string = json.choices[0].delta.content || '\n';
|
||||
// console.log('content:', content)
|
||||
res.write(`event: responseData\ndata: ${content.replace(/\n/g, '<br/>')}\n\n`);
|
||||
AIResponse += content;
|
||||
|
@@ -61,13 +61,11 @@ const RegisterForm = ({ setPageType, loginSuccess }: Props) => {
|
||||
title: `密码已找回`,
|
||||
status: 'success'
|
||||
});
|
||||
} catch (error) {
|
||||
typeof error === 'string' &&
|
||||
toast({
|
||||
title: error,
|
||||
status: 'error',
|
||||
position: 'top'
|
||||
});
|
||||
} catch (error: any) {
|
||||
toast({
|
||||
title: error.message || '修改密码异常',
|
||||
status: 'error'
|
||||
});
|
||||
}
|
||||
setRequesting(false);
|
||||
},
|
||||
|
@@ -42,13 +42,11 @@ const LoginForm = ({ setPageType, loginSuccess }: Props) => {
|
||||
title: '登录成功',
|
||||
status: 'success'
|
||||
});
|
||||
} catch (error) {
|
||||
typeof error === 'string' &&
|
||||
toast({
|
||||
title: error,
|
||||
status: 'error',
|
||||
position: 'top'
|
||||
});
|
||||
} catch (error: any) {
|
||||
toast({
|
||||
title: error.message || '登录异常',
|
||||
status: 'error'
|
||||
});
|
||||
}
|
||||
setRequesting(false);
|
||||
},
|
||||
|
@@ -61,14 +61,11 @@ const RegisterForm = ({ setPageType, loginSuccess }: Props) => {
|
||||
title: `注册成功`,
|
||||
status: 'success'
|
||||
});
|
||||
} catch (error) {
|
||||
typeof error === 'string' &&
|
||||
toast({
|
||||
title: error,
|
||||
status: 'error',
|
||||
duration: 4000,
|
||||
isClosable: true
|
||||
});
|
||||
} catch (error: any) {
|
||||
toast({
|
||||
title: error.message || '注册异常',
|
||||
status: 'error'
|
||||
});
|
||||
}
|
||||
setRequesting(false);
|
||||
},
|
||||
|
@@ -1,4 +1,4 @@
|
||||
import React, { useState, useCallback, useMemo } from 'react';
|
||||
import React, { useState, useCallback, useEffect } from 'react';
|
||||
import styles from './index.module.scss';
|
||||
import { Box, Flex, Image } from '@chakra-ui/react';
|
||||
import { PageTypeEnum } from '@/constants/user';
|
||||
@@ -21,7 +21,7 @@ const Login = () => {
|
||||
const loginSuccess = useCallback(
|
||||
(res: ResLogin) => {
|
||||
setUserInfo(res.user, res.token);
|
||||
router.push('/');
|
||||
router.push('/model/list');
|
||||
},
|
||||
[router, setUserInfo]
|
||||
);
|
||||
@@ -38,6 +38,10 @@ const Login = () => {
|
||||
return <Component setPageType={setPageType} loginSuccess={loginSuccess} />;
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
router.prefetch('/model/list');
|
||||
}, [router]);
|
||||
|
||||
return (
|
||||
<Box className={styles.loginPage} h={'100%'} p={isPc ? '10vh 10vw' : 0}>
|
||||
<Flex
|
||||
|
@@ -120,11 +120,15 @@ const ModelDetail = () => {
|
||||
try {
|
||||
await putModelTrainingStatus(model._id);
|
||||
loadModel();
|
||||
} catch (error) {
|
||||
} catch (error: any) {
|
||||
console.error(error);
|
||||
toast({
|
||||
title: error.message || '更新失败',
|
||||
status: 'error'
|
||||
});
|
||||
}
|
||||
setLoading(false);
|
||||
}, [setLoading, loadModel, model]);
|
||||
}, [model, setLoading, loadModel, toast]);
|
||||
|
||||
return (
|
||||
<>
|
||||
|
@@ -10,10 +10,12 @@ import { useScreen } from '@/hooks/useScreen';
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { useLoading } from '@/hooks/useLoading';
|
||||
import dynamic from 'next/dynamic';
|
||||
import { useToast } from '@/hooks/useToast';
|
||||
|
||||
const CreateModel = dynamic(() => import('./components/CreateModel'));
|
||||
|
||||
const ModelList = () => {
|
||||
const { toast } = useToast();
|
||||
const { isPc } = useScreen();
|
||||
const router = useRouter();
|
||||
const [models, setModels] = useState<ModelType[]>([]);
|
||||
@@ -43,12 +45,16 @@ const ModelList = () => {
|
||||
router.push(`/chat?chatId=${chatId}`, undefined, {
|
||||
shallow: true
|
||||
});
|
||||
} catch (err) {
|
||||
} catch (err: any) {
|
||||
console.error(err);
|
||||
toast({
|
||||
title: err.message || '出现一些异常',
|
||||
status: 'error'
|
||||
});
|
||||
}
|
||||
setIsLoading(false);
|
||||
},
|
||||
[router, setIsLoading]
|
||||
[router, setIsLoading, toast]
|
||||
);
|
||||
|
||||
return (
|
||||
|
@@ -1,18 +1,16 @@
|
||||
import mongoose from 'mongoose';
|
||||
import mongoose, { Mongoose } from 'mongoose';
|
||||
|
||||
/**
|
||||
* 连接 MongoDB 数据库
|
||||
*/
|
||||
export async function connectToDatabase(): Promise<void> {
|
||||
// @ts-ignore
|
||||
if (global.mongodb) {
|
||||
return;
|
||||
}
|
||||
// @ts-ignore
|
||||
|
||||
global.mongodb = 'connecting';
|
||||
console.log('connect mongo');
|
||||
try {
|
||||
// @ts-ignore
|
||||
global.mongodb = await mongoose.connect(process.env.MONGODB_URI as string, {
|
||||
dbName: 'doc_gpt',
|
||||
maxPoolSize: 10,
|
||||
@@ -20,7 +18,6 @@ export async function connectToDatabase(): Promise<void> {
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('mongo connect error');
|
||||
// @ts-ignore
|
||||
global.mongodb = null;
|
||||
}
|
||||
}
|
||||
|
8
src/types/index.d.ts
vendored
8
src/types/index.d.ts
vendored
@@ -1,9 +1,9 @@
|
||||
import type { Mongoose } from 'mongoose';
|
||||
|
||||
declare global {
|
||||
interface Global {
|
||||
mongodb: Mongoose;
|
||||
namespace NodeJS {
|
||||
interface Global {
|
||||
mongodb: Mongoose | string;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export type a = string;
|
||||
|
Reference in New Issue
Block a user