mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-22 12:20:34 +00:00
fix: chat data outsize
This commit is contained in:
@@ -11,6 +11,7 @@ import SideTabs from '@/components/SideTabs';
|
||||
import Tabs from '@/components/Tabs';
|
||||
import UserInfo from './components/Info';
|
||||
import { serviceSideProps } from '@/utils/i18n';
|
||||
import { feConfigs } from '@/store/static';
|
||||
|
||||
const BillTable = dynamic(() => import('./components/BillTable'), {
|
||||
ssr: false
|
||||
|
@@ -52,7 +52,7 @@ export const jsonRes = <T = any>(
|
||||
} else if (openaiError[error?.response?.statusText]) {
|
||||
msg = openaiError[error.response.statusText];
|
||||
}
|
||||
console.log(error);
|
||||
console.log(error?.response);
|
||||
}
|
||||
|
||||
res.status(code).json({
|
||||
@@ -92,7 +92,7 @@ export const sseErrRes = (res: NextApiResponse, error: any) => {
|
||||
} else if (openaiError[error?.response?.statusText]) {
|
||||
msg = openaiError[error.response.statusText];
|
||||
}
|
||||
console.log('sse error => ', error);
|
||||
console.log('sse error => ', error?.response);
|
||||
|
||||
sseResponse({
|
||||
res,
|
||||
|
@@ -23,54 +23,68 @@ export async function saveChat({
|
||||
shareId,
|
||||
content
|
||||
}: Props) {
|
||||
const chatHistory = await Chat.findOne(
|
||||
{
|
||||
chatId,
|
||||
userId
|
||||
},
|
||||
'_id'
|
||||
);
|
||||
|
||||
const promise = [];
|
||||
|
||||
if (chatHistory) {
|
||||
promise.push(
|
||||
Chat.updateOne(
|
||||
{ chatId, userId },
|
||||
{
|
||||
$push: {
|
||||
content: {
|
||||
$each: content,
|
||||
$slice: -50
|
||||
}
|
||||
},
|
||||
title: content[0].value.slice(0, 20),
|
||||
updateTime: new Date()
|
||||
}
|
||||
)
|
||||
);
|
||||
} else {
|
||||
promise.push(
|
||||
Chat.create({
|
||||
try {
|
||||
const chatHistory = await Chat.findOne(
|
||||
{
|
||||
chatId,
|
||||
userId,
|
||||
appId,
|
||||
variables,
|
||||
title: content[0].value.slice(0, 20),
|
||||
source,
|
||||
shareId,
|
||||
content: content
|
||||
})
|
||||
userId
|
||||
},
|
||||
'_id'
|
||||
);
|
||||
|
||||
const promise = [];
|
||||
|
||||
if (chatHistory) {
|
||||
promise.push(
|
||||
Chat.updateOne(
|
||||
{ chatId, userId },
|
||||
{
|
||||
$push: {
|
||||
content: {
|
||||
$each: content,
|
||||
$slice: -40
|
||||
}
|
||||
},
|
||||
title: content[0].value.slice(0, 20),
|
||||
updateTime: new Date()
|
||||
}
|
||||
)
|
||||
);
|
||||
} else {
|
||||
promise.push(
|
||||
Chat.create({
|
||||
chatId,
|
||||
userId,
|
||||
appId,
|
||||
variables,
|
||||
title: content[0].value.slice(0, 20),
|
||||
source,
|
||||
shareId,
|
||||
content: content
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
if (isOwner && source === ChatSourceEnum.online) {
|
||||
promise.push(
|
||||
App.findByIdAndUpdate(appId, {
|
||||
updateTime: new Date()
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
await Promise.all(promise);
|
||||
} catch (error) {
|
||||
Chat.updateOne(
|
||||
{ chatId, userId },
|
||||
{
|
||||
$push: {
|
||||
content: {
|
||||
$each: [],
|
||||
$slice: -10
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
if (isOwner && source === ChatSourceEnum.online) {
|
||||
promise.push(
|
||||
App.findByIdAndUpdate(appId, {
|
||||
updateTime: new Date()
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
await Promise.all(promise);
|
||||
}
|
||||
|
Reference in New Issue
Block a user