feat: add chat message
This commit is contained in:
@@ -86,6 +86,7 @@ AiAgent.init(
|
||||
{
|
||||
sequelize,
|
||||
tableName: 'ai_agent',
|
||||
paranoid: true,
|
||||
},
|
||||
);
|
||||
AiAgent.sync({ alter: true, logging: false }).catch((e) => {
|
||||
|
||||
@@ -12,6 +12,9 @@ export class ChatHistory extends Model {
|
||||
declare root: boolean;
|
||||
declare show: boolean;
|
||||
declare uid: string;
|
||||
declare chatId: string;
|
||||
declare chatPromptId: string;
|
||||
declare role: string;
|
||||
}
|
||||
|
||||
ChatHistory.init(
|
||||
@@ -37,6 +40,11 @@ ChatHistory.init(
|
||||
type: DataTypes.BOOLEAN, // 是否是根节点
|
||||
defaultValue: false,
|
||||
},
|
||||
role: {
|
||||
type: DataTypes.STRING, // 角色
|
||||
allowNull: true,
|
||||
defaultValue: 'user',
|
||||
},
|
||||
show: {
|
||||
type: DataTypes.BOOLEAN, // 当创建返回的时候,配置是否显示
|
||||
defaultValue: true,
|
||||
@@ -53,6 +61,6 @@ ChatHistory.init(
|
||||
);
|
||||
|
||||
// force 只能run一次,否则会删除表
|
||||
ChatHistory.sync({ alter: true, force: true, logging: false }).catch((e) => {
|
||||
ChatHistory.sync({ alter: true, logging: false }).catch((e) => {
|
||||
console.error('History sync error', e);
|
||||
});
|
||||
|
||||
@@ -7,6 +7,7 @@ export type ChatPromptData = {
|
||||
aiAgentId: string;
|
||||
// 使用那个初始化的prompt,如果不存在则纯粹的白对话。
|
||||
promptId?: string;
|
||||
chainPromptId?: string;
|
||||
};
|
||||
/**
|
||||
* chat绑定就的agent和prompt
|
||||
@@ -18,7 +19,7 @@ export class ChatPrompt extends Model {
|
||||
declare description: string;
|
||||
declare uid: string;
|
||||
declare key: string;
|
||||
declare data: string;
|
||||
declare data: ChatPromptData;
|
||||
}
|
||||
|
||||
ChatPrompt.init(
|
||||
@@ -43,6 +44,7 @@ ChatPrompt.init(
|
||||
key: {
|
||||
type: DataTypes.STRING, // 页面属于 /container/edit/list
|
||||
allowNull: false,
|
||||
defaultValue: '',
|
||||
},
|
||||
uid: {
|
||||
type: DataTypes.STRING,
|
||||
@@ -52,10 +54,11 @@ ChatPrompt.init(
|
||||
{
|
||||
sequelize, // 传入 Sequelize 实例
|
||||
modelName: 'chat_prompt', // 模型名称
|
||||
paranoid: true,
|
||||
},
|
||||
);
|
||||
|
||||
// force 只能run一次,否则会删除表
|
||||
ChatPrompt.sync({ alter: true, force: true, logging: false }).catch((e) => {
|
||||
ChatPrompt.sync({ alter: true, logging: false }).catch((e) => {
|
||||
console.error('Prompt sync error', e);
|
||||
});
|
||||
|
||||
61
src/models/chat-session.ts
Normal file
61
src/models/chat-session.ts
Normal file
@@ -0,0 +1,61 @@
|
||||
import { sequelize } from '../modules/sequelize.ts';
|
||||
import { DataTypes, Model } from 'sequelize';
|
||||
|
||||
/**
|
||||
* chat 回话记录
|
||||
* 有一些内容是预置的。
|
||||
*/
|
||||
export class ChatSession extends Model {
|
||||
declare id: string;
|
||||
declare data: string;
|
||||
declare chatPromptId: string;
|
||||
declare type: string;
|
||||
declare key: string;
|
||||
declare title: string;
|
||||
declare uid: string;
|
||||
}
|
||||
|
||||
ChatSession.init(
|
||||
{
|
||||
id: {
|
||||
type: DataTypes.UUID,
|
||||
primaryKey: true,
|
||||
defaultValue: DataTypes.UUIDV4,
|
||||
},
|
||||
data: {
|
||||
type: DataTypes.JSON,
|
||||
allowNull: true,
|
||||
defaultValue: {},
|
||||
},
|
||||
chatPromptId: {
|
||||
type: DataTypes.UUID, // 属于哪一个prompt
|
||||
allowNull: true,
|
||||
},
|
||||
type: {
|
||||
type: DataTypes.STRING, // 属于测试的,还是正式的
|
||||
defaultValue: 'production',
|
||||
},
|
||||
title: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: true,
|
||||
defaultValue: '',
|
||||
},
|
||||
key: {
|
||||
type: DataTypes.STRING, // 页面属于 /container/edit/list
|
||||
allowNull: true,
|
||||
},
|
||||
uid: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
sequelize, // 传入 Sequelize 实例
|
||||
modelName: 'chat_session', // 模型名称
|
||||
},
|
||||
);
|
||||
|
||||
// force 只能run一次,否则会删除表
|
||||
ChatSession.sync({ alter: true, logging: false }).catch((e) => {
|
||||
console.error('Sessuib sync error', e);
|
||||
});
|
||||
@@ -91,9 +91,14 @@ RouterCodeModel.init(
|
||||
{
|
||||
sequelize,
|
||||
tableName: 'cf_router_code', // container flow router code
|
||||
paranoid: true,
|
||||
},
|
||||
);
|
||||
RouterCodeModel.sync({ alter: true, logging: false }).catch((e) => {
|
||||
console.error('RouterCodeModel sync', e);
|
||||
});
|
||||
RouterCodeModel.sync({ alter: true, logging: false })
|
||||
.then((res) => {
|
||||
console.log('RouterCodeModel sync', res);
|
||||
})
|
||||
.catch((e) => {
|
||||
console.error('RouterCodeModel sync', e);
|
||||
});
|
||||
// RouterCodeModel.sync({force: true});
|
||||
|
||||
@@ -57,6 +57,7 @@ Prompt.init(
|
||||
{
|
||||
sequelize, // 传入 Sequelize 实例
|
||||
modelName: 'prompt', // 模型名称
|
||||
paranoid: true,
|
||||
},
|
||||
);
|
||||
|
||||
|
||||
@@ -24,7 +24,9 @@ export class User extends Model {
|
||||
return { token, expireTime: now + expireTime };
|
||||
}
|
||||
static async verifyToken(token: string) {
|
||||
return await checkToken(token, config.tokenSecret);
|
||||
const ct = await checkToken(token, config.tokenSecret);
|
||||
const tokenUser = ct.payload;
|
||||
return tokenUser;
|
||||
}
|
||||
static createUser(username: string, password?: string, description?: string) {
|
||||
const user = User.findOne({ where: { username } });
|
||||
@@ -79,6 +81,7 @@ User.init(
|
||||
{
|
||||
sequelize,
|
||||
tableName: 'cf_user',
|
||||
paranoid: true,
|
||||
},
|
||||
);
|
||||
User.sync({ alter: true, logging: false })
|
||||
|
||||
Reference in New Issue
Block a user