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