mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-23 05:12:39 +00:00
4.6.4-alpha (#569)
This commit is contained in:
@@ -50,10 +50,6 @@ const ChatSchema = new Schema({
|
||||
top: {
|
||||
type: Boolean
|
||||
},
|
||||
variables: {
|
||||
type: Object,
|
||||
default: {}
|
||||
},
|
||||
source: {
|
||||
type: String,
|
||||
enum: Object.keys(ChatSourceMap),
|
||||
@@ -62,9 +58,17 @@ const ChatSchema = new Schema({
|
||||
shareId: {
|
||||
type: String
|
||||
},
|
||||
isInit: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
outLinkUid: {
|
||||
type: String
|
||||
},
|
||||
variables: {
|
||||
type: Object,
|
||||
default: {}
|
||||
},
|
||||
metadata: {
|
||||
//For special storage
|
||||
type: Object,
|
||||
default: {}
|
||||
},
|
||||
content: {
|
||||
type: [
|
||||
@@ -89,9 +93,10 @@ const ChatSchema = new Schema({
|
||||
});
|
||||
|
||||
try {
|
||||
ChatSchema.index({ tmbId: 1 });
|
||||
ChatSchema.index({ updateTime: -1 });
|
||||
ChatSchema.index({ appId: 1 });
|
||||
ChatSchema.index({ tmbId: 1 });
|
||||
ChatSchema.index({ shareId: 1 });
|
||||
ChatSchema.index({ updateTime: -1 });
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
|
22
packages/service/core/chat/controller.ts
Normal file
22
packages/service/core/chat/controller.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import type { ChatItemType } from '@fastgpt/global/core/chat/type';
|
||||
import { MongoChatItem } from './chatItemSchema';
|
||||
|
||||
export async function getChatItems({
|
||||
chatId,
|
||||
limit = 30,
|
||||
field
|
||||
}: {
|
||||
chatId?: string;
|
||||
limit?: number;
|
||||
field: string;
|
||||
}): Promise<{ history: ChatItemType[] }> {
|
||||
if (!chatId) {
|
||||
return { history: [] };
|
||||
}
|
||||
|
||||
const history = await MongoChatItem.find({ chatId }, field).sort({ _id: -1 }).limit(limit);
|
||||
|
||||
history.reverse();
|
||||
|
||||
return { history };
|
||||
}
|
Reference in New Issue
Block a user