code-center/src/models/chat-session.ts
2024-10-01 00:47:14 +08:00

62 lines
1.3 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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