mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-27 08:25:07 +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 Tabs from '@/components/Tabs';
|
||||||
import UserInfo from './components/Info';
|
import UserInfo from './components/Info';
|
||||||
import { serviceSideProps } from '@/utils/i18n';
|
import { serviceSideProps } from '@/utils/i18n';
|
||||||
|
import { feConfigs } from '@/store/static';
|
||||||
|
|
||||||
const BillTable = dynamic(() => import('./components/BillTable'), {
|
const BillTable = dynamic(() => import('./components/BillTable'), {
|
||||||
ssr: false
|
ssr: false
|
||||||
|
@@ -52,7 +52,7 @@ export const jsonRes = <T = any>(
|
|||||||
} else if (openaiError[error?.response?.statusText]) {
|
} else if (openaiError[error?.response?.statusText]) {
|
||||||
msg = openaiError[error.response.statusText];
|
msg = openaiError[error.response.statusText];
|
||||||
}
|
}
|
||||||
console.log(error);
|
console.log(error?.response);
|
||||||
}
|
}
|
||||||
|
|
||||||
res.status(code).json({
|
res.status(code).json({
|
||||||
@@ -92,7 +92,7 @@ export const sseErrRes = (res: NextApiResponse, error: any) => {
|
|||||||
} else if (openaiError[error?.response?.statusText]) {
|
} else if (openaiError[error?.response?.statusText]) {
|
||||||
msg = openaiError[error.response.statusText];
|
msg = openaiError[error.response.statusText];
|
||||||
}
|
}
|
||||||
console.log('sse error => ', error);
|
console.log('sse error => ', error?.response);
|
||||||
|
|
||||||
sseResponse({
|
sseResponse({
|
||||||
res,
|
res,
|
||||||
|
@@ -23,54 +23,68 @@ export async function saveChat({
|
|||||||
shareId,
|
shareId,
|
||||||
content
|
content
|
||||||
}: Props) {
|
}: Props) {
|
||||||
const chatHistory = await Chat.findOne(
|
try {
|
||||||
{
|
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({
|
|
||||||
chatId,
|
chatId,
|
||||||
userId,
|
userId
|
||||||
appId,
|
},
|
||||||
variables,
|
'_id'
|
||||||
title: content[0].value.slice(0, 20),
|
);
|
||||||
source,
|
|
||||||
shareId,
|
const promise = [];
|
||||||
content: content
|
|
||||||
})
|
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