62 lines
1.3 KiB
TypeScript
62 lines
1.3 KiB
TypeScript
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);
|
||
});
|