feat: 复制和删除对话功能

This commit is contained in:
archer
2023-03-26 13:14:50 +08:00
parent 936e36205e
commit 41b6401c13
18 changed files with 146 additions and 116 deletions

View File

@@ -1,9 +1,10 @@
export const openaiError: Record<string, string> = {
context_length_exceeded: '内容超长了,请重置对话',
Unauthorized: 'API-KEY 不合法',
rate_limit_reached: '同时访问用户过多,请稍后再试',
rate_limit_reached: 'API被限制,请稍后再试',
'Bad Request': 'Bad Request~ 可能内容太多了',
'Too Many Requests': '请求次数太多了,请慢点~'
'Too Many Requests': '请求次数太多了,请慢点~',
'Bad Gateway': '网关异常,请重试'
};
export const proxyError: Record<string, boolean> = {
ECONNABORTED: true,

View File

@@ -23,8 +23,8 @@ const ChatSchema = new Schema({
required: true
},
updateTime: {
type: Number,
required: true
type: Date,
default: () => new Date()
},
isShare: {
type: Boolean,
@@ -41,6 +41,10 @@ const ChatSchema = new Schema({
value: {
type: String,
required: true
},
deleted: {
type: Boolean,
default: false
}
}
],

View File

@@ -52,7 +52,7 @@ const ModelSchema = new Schema({
trainId: {
// 训练时需要的 ID
type: String,
required: true
required: false
},
chatModel: {
// 聊天时使用的模型

View File

@@ -28,11 +28,11 @@ export const jsonRes = <T = any>(
} else if (openaiError[error?.response?.statusText]) {
msg = openaiError[error.response.statusText];
}
error?.response && console.log('chat err:', error?.response);
console.log('error->');
console.log('code:', error.code);
console.log('statusText:', error?.response?.statusText);
console.log('msg:', msg);
error?.response && console.log('chat err:', error?.response);
}
res.json({

View File

@@ -51,6 +51,9 @@ export const authChat = async (chatId: string, authorization?: string) => {
return Promise.reject('该账号余额不足');
}
// filter 掉被 deleted 的内容
chat.content = chat.content.filter((item) => item.deleted !== true);
return {
userApiKey,
systemKey: process.env.OPENAIKEY as string,