feat: add chat message

This commit is contained in:
2024-10-01 00:47:14 +08:00
parent e05c042827
commit bd38ad2eaa
20 changed files with 556 additions and 10 deletions

View 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);
});