feat:自定义历史聊天标题 (#41)

* feat:自定义历史聊天标题

* Update chat.ts

* perf:自定义聊天标题

* feat: google auth

* perf:将修改标题移入右键菜单

* perf:updatetitle

---------

Co-authored-by: archer <545436317@qq.com>
This commit is contained in:
Textcat
2023-05-29 20:36:28 +08:00
committed by GitHub
parent e818cb037f
commit 7fe39c2515
6 changed files with 169 additions and 11 deletions

View File

@@ -78,13 +78,14 @@ export async function saveChat({
return _id;
} else {
// 已经有记录,追加入库
const chat = await Chat.findById(chatId);
await Chat.findByIdAndUpdate(chatId, {
$push: {
content: {
$each: content
}
},
title: content[0].value.slice(0, 20),
...(chat && !chat.customTitle ? { title: content[0].value.slice(0, 20) } : {}),
latestChat: content[1].value,
updateTime: new Date()
});

View File

@@ -0,0 +1,36 @@
import type { NextApiRequest, NextApiResponse } from 'next';
import { jsonRes } from '@/service/response';
import { connectToDatabase, Chat } from '@/service/mongo';
import { authModel } from '@/service/utils/auth';
import { authUser } from '@/service/utils/auth';
/* 更新聊天标题 */
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
try {
const { chatId, modelId, newTitle } = req.body as {
chatId: '' | string;
modelId: '' | string;
newTitle: string;
};
const { userId } = await authUser({ req, authToken: true });
await connectToDatabase();
await authModel({ modelId, userId, authOwner: false });
await Chat.findByIdAndUpdate(
chatId,
{
title: newTitle,
customTitle: true
} // 自定义标题}
);
jsonRes(res);
} catch (err) {
jsonRes(res, {
code: 500,
error: err
});
}
}