mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-23 13:03:50 +00:00
perf: mongo index;fix: loading status and abort chat, system prompt empty
This commit is contained in:
@@ -50,7 +50,7 @@ export const streamFetch = ({ url, data, onMessage, abortSignal }: StreamFetchPr
|
|||||||
read();
|
read();
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
if (err?.message === 'The user aborted a request.') {
|
if (err?.message === 'The user aborted a request.') {
|
||||||
return resolve({ responseText, newChatId, quoteLen, systemPrompt: '' });
|
return resolve({ responseText, newChatId, quoteLen, systemPrompt });
|
||||||
}
|
}
|
||||||
reject(typeof err === 'string' ? err : err?.message || '请求异常');
|
reject(typeof err === 'string' ? err : err?.message || '请求异常');
|
||||||
}
|
}
|
||||||
|
@@ -26,7 +26,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
|
|||||||
userId
|
userId
|
||||||
});
|
});
|
||||||
if (authCount >= 30) {
|
if (authCount >= 30) {
|
||||||
throw new Error('上限 30 个助手');
|
throw new Error('上限 30 个应用');
|
||||||
}
|
}
|
||||||
|
|
||||||
// 创建模型
|
// 创建模型
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
import type { NextApiRequest, NextApiResponse } from 'next';
|
import type { NextApiRequest, NextApiResponse } from 'next';
|
||||||
import { jsonRes } from '@/service/response';
|
import { jsonRes } from '@/service/response';
|
||||||
import { connectToDatabase, Collection, Model } from '@/service/mongo';
|
import { connectToDatabase, Model } from '@/service/mongo';
|
||||||
import type { PagingData } from '@/types';
|
import type { PagingData } from '@/types';
|
||||||
import type { ShareModelItem } from '@/types/model';
|
import type { ShareModelItem } from '@/types/model';
|
||||||
import { parseCookie } from '@/service/utils/auth';
|
import { parseCookie } from '@/service/utils/auth';
|
||||||
|
@@ -16,18 +16,18 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
|||||||
|
|
||||||
await connectToDatabase();
|
await connectToDatabase();
|
||||||
|
|
||||||
// 根据 id 获取用户账单
|
const where = {
|
||||||
const bills = await Bill.find({
|
|
||||||
userId
|
userId
|
||||||
})
|
};
|
||||||
.sort({ _id: -1 }) // 按照创建时间倒序排列
|
|
||||||
.skip((pageNum - 1) * pageSize)
|
|
||||||
.limit(pageSize);
|
|
||||||
|
|
||||||
// 获取total
|
// get bill record and total by record
|
||||||
const total = await Bill.countDocuments({
|
const [bills, total] = await Promise.all([
|
||||||
userId
|
Bill.find(where)
|
||||||
});
|
.sort({ time: -1 }) // 按照创建时间倒序排列
|
||||||
|
.skip((pageNum - 1) * pageSize)
|
||||||
|
.limit(pageSize),
|
||||||
|
Bill.countDocuments(where)
|
||||||
|
]);
|
||||||
|
|
||||||
jsonRes(res, {
|
jsonRes(res, {
|
||||||
data: {
|
data: {
|
||||||
|
@@ -24,7 +24,7 @@ const KbList = ({ kbId }: { kbId: string }) => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
/* 加载模型 */
|
/* 加载模型 */
|
||||||
const { isLoading } = useQuery(['loadModels'], () => loadKbList(false));
|
const { isFetching } = useQuery(['loadModels'], () => loadKbList(false));
|
||||||
|
|
||||||
const handleCreateModel = useCallback(async () => {
|
const handleCreateModel = useCallback(async () => {
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
@@ -133,7 +133,7 @@ const KbList = ({ kbId }: { kbId: string }) => {
|
|||||||
</Flex>
|
</Flex>
|
||||||
))}
|
))}
|
||||||
|
|
||||||
{!isLoading && myKbList.length === 0 && (
|
{!isFetching && myKbList.length === 0 && (
|
||||||
<Flex h={'100%'} flexDirection={'column'} alignItems={'center'} pt={'30vh'}>
|
<Flex h={'100%'} flexDirection={'column'} alignItems={'center'} pt={'30vh'}>
|
||||||
<MyIcon name="empty" w={'48px'} h={'48px'} color={'transparent'} />
|
<MyIcon name="empty" w={'48px'} h={'48px'} color={'transparent'} />
|
||||||
<Box mt={2} color={'myGray.500'}>
|
<Box mt={2} color={'myGray.500'}>
|
||||||
@@ -142,7 +142,7 @@ const KbList = ({ kbId }: { kbId: string }) => {
|
|||||||
</Flex>
|
</Flex>
|
||||||
)}
|
)}
|
||||||
</Box>
|
</Box>
|
||||||
<Loading loading={isLoading} fixed={false} />
|
<Loading loading={isFetching} fixed={false} />
|
||||||
</Flex>
|
</Flex>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@@ -19,7 +19,7 @@ const ModelList = ({ modelId }: { modelId: string }) => {
|
|||||||
const [searchText, setSearchText] = useState('');
|
const [searchText, setSearchText] = useState('');
|
||||||
|
|
||||||
/* 加载模型 */
|
/* 加载模型 */
|
||||||
const { isLoading } = useQuery(['loadModels'], () => loadMyModels(false));
|
const { isFetching } = useQuery(['loadModels'], () => loadMyModels(false));
|
||||||
|
|
||||||
const onclickCreateModel = useCallback(async () => {
|
const onclickCreateModel = useCallback(async () => {
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
@@ -77,7 +77,7 @@ const ModelList = ({ modelId }: { modelId: string }) => {
|
|||||||
<Flex flex={1} mr={2} position={'relative'} alignItems={'center'}>
|
<Flex flex={1} mr={2} position={'relative'} alignItems={'center'}>
|
||||||
<Input
|
<Input
|
||||||
h={'32px'}
|
h={'32px'}
|
||||||
placeholder="搜索 AI 助手"
|
placeholder="搜索 AI 应用"
|
||||||
value={searchText}
|
value={searchText}
|
||||||
onChange={(e) => setSearchText(e.target.value)}
|
onChange={(e) => setSearchText(e.target.value)}
|
||||||
/>
|
/>
|
||||||
@@ -149,16 +149,16 @@ const ModelList = ({ modelId }: { modelId: string }) => {
|
|||||||
</Box>
|
</Box>
|
||||||
))}
|
))}
|
||||||
|
|
||||||
{!isLoading && totalModels === 0 && (
|
{!isFetching && totalModels === 0 && (
|
||||||
<Flex h={'100%'} flexDirection={'column'} alignItems={'center'} pt={'30vh'}>
|
<Flex h={'100%'} flexDirection={'column'} alignItems={'center'} pt={'30vh'}>
|
||||||
<MyIcon name="empty" w={'48px'} h={'48px'} color={'transparent'} />
|
<MyIcon name="empty" w={'48px'} h={'48px'} color={'transparent'} />
|
||||||
<Box mt={2} color={'myGray.500'}>
|
<Box mt={2} color={'myGray.500'}>
|
||||||
还没有 AI 助手~
|
还没有 AI 应用~
|
||||||
</Box>
|
</Box>
|
||||||
</Flex>
|
</Flex>
|
||||||
)}
|
)}
|
||||||
</Box>
|
</Box>
|
||||||
<Loading loading={isLoading} fixed={false} />
|
<Loading loading={isFetching} fixed={false} />
|
||||||
</Flex>
|
</Flex>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@@ -43,4 +43,11 @@ const BillSchema = new Schema({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
try {
|
||||||
|
BillSchema.index({ time: -1 });
|
||||||
|
BillSchema.index({ userId: 1 });
|
||||||
|
} catch (error) {
|
||||||
|
error;
|
||||||
|
}
|
||||||
|
|
||||||
export const Bill: Model<BillType> = models['bill'] || model('bill', BillSchema);
|
export const Bill: Model<BillType> = models['bill'] || model('bill', BillSchema);
|
||||||
|
@@ -82,4 +82,11 @@ const ModelSchema = new Schema({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
try {
|
||||||
|
ModelSchema.index({ updateTime: -1 });
|
||||||
|
ModelSchema.index({ 'share.collection': -1 });
|
||||||
|
} catch (error) {
|
||||||
|
error;
|
||||||
|
}
|
||||||
|
|
||||||
export const Model: MongoModel<ModelType> = models['model'] || model('model', ModelSchema);
|
export const Model: MongoModel<ModelType> = models['model'] || model('model', ModelSchema);
|
||||||
|
Reference in New Issue
Block a user