mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-26 15:50:25 +00:00
feat: 修改chat的数据结构
This commit is contained in:
@@ -20,7 +20,24 @@ const ChatSchema = new Schema({
|
||||
// 剩余加载次数
|
||||
type: Number,
|
||||
required: true
|
||||
}
|
||||
},
|
||||
updateTime: {
|
||||
type: Number,
|
||||
required: true
|
||||
},
|
||||
content: [
|
||||
{
|
||||
obj: {
|
||||
type: String,
|
||||
required: true,
|
||||
enum: ['Human', 'AI', 'SYSTEM']
|
||||
},
|
||||
value: {
|
||||
type: String,
|
||||
required: true
|
||||
}
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
export const Chat = models['chat'] || model('chat', ChatSchema);
|
||||
|
@@ -1,28 +0,0 @@
|
||||
import { Schema, model, models } from 'mongoose';
|
||||
|
||||
const ChatWindowSchema = new Schema({
|
||||
chatId: {
|
||||
type: Schema.Types.ObjectId,
|
||||
ref: 'chat',
|
||||
required: true
|
||||
},
|
||||
updateTime: {
|
||||
type: Number,
|
||||
required: true
|
||||
},
|
||||
content: [
|
||||
{
|
||||
obj: {
|
||||
type: String,
|
||||
required: true,
|
||||
enum: ['Human', 'AI', 'SYSTEM']
|
||||
},
|
||||
value: {
|
||||
type: String,
|
||||
required: true
|
||||
}
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
export const ChatWindow = models['chatWindow'] || model('chatWindow', ChatWindowSchema);
|
@@ -30,4 +30,3 @@ export * from './models/chat';
|
||||
export * from './models/model';
|
||||
export * from './models/user';
|
||||
export * from './models/training';
|
||||
export * from './models/chatWindow';
|
||||
|
@@ -7,12 +7,12 @@ export interface ResponseType<T = any> {
|
||||
data: T;
|
||||
}
|
||||
|
||||
export const jsonRes = (
|
||||
export const jsonRes = <T = any>(
|
||||
res: NextApiResponse,
|
||||
props?: {
|
||||
code?: number;
|
||||
message?: string;
|
||||
data?: any;
|
||||
data?: T;
|
||||
error?: any;
|
||||
}
|
||||
) => {
|
||||
|
@@ -1,5 +1,6 @@
|
||||
import { Configuration, OpenAIApi } from 'openai';
|
||||
import { Chat } from '../mongo';
|
||||
import type { ChatPopulate } from '@/types/mongoSchema';
|
||||
|
||||
export const getOpenAIApi = (apiKey: string) => {
|
||||
const configuration = new Configuration({
|
||||
@@ -11,7 +12,7 @@ export const getOpenAIApi = (apiKey: string) => {
|
||||
|
||||
export const authChat = async (chatId: string) => {
|
||||
// 获取 chat 数据
|
||||
const chat = await Chat.findById(chatId)
|
||||
const chat = await Chat.findById<ChatPopulate>(chatId)
|
||||
.populate({
|
||||
path: 'modelId',
|
||||
options: {
|
||||
@@ -26,7 +27,12 @@ export const authChat = async (chatId: string) => {
|
||||
});
|
||||
|
||||
if (!chat || !chat.modelId || !chat.userId) {
|
||||
return Promise.reject('聊天已过期');
|
||||
return Promise.reject('模型不存在');
|
||||
}
|
||||
|
||||
// 安全校验
|
||||
if (chat.loadAmount === 0 || chat.expiredTime <= Date.now()) {
|
||||
return Promise.reject('聊天框已过期');
|
||||
}
|
||||
|
||||
// 获取 user 的 apiKey
|
||||
|
Reference in New Issue
Block a user