59 lines
1.3 KiB
TypeScript
59 lines
1.3 KiB
TypeScript
import { chat } from '@/modules/ollama.ts';
|
||
import { sequelize } from '../modules/sequelize.ts';
|
||
import { DataTypes, Model } from 'sequelize';
|
||
|
||
/**
|
||
* chat 回话记录
|
||
* 有一些内容是预置的。
|
||
*/
|
||
export class ChatHistory extends Model {
|
||
declare id: string;
|
||
declare data: string;
|
||
declare root: boolean;
|
||
declare show: boolean;
|
||
declare uid: string;
|
||
}
|
||
|
||
ChatHistory.init(
|
||
{
|
||
id: {
|
||
type: DataTypes.UUID,
|
||
primaryKey: true,
|
||
defaultValue: DataTypes.UUIDV4,
|
||
},
|
||
data: {
|
||
type: DataTypes.JSON,
|
||
allowNull: true,
|
||
},
|
||
chatId: {
|
||
type: DataTypes.UUID, // 历史属于哪一条会话
|
||
allowNull: true,
|
||
},
|
||
chatPromptId: {
|
||
type: DataTypes.UUID, // 属于哪一个prompt
|
||
allowNull: true,
|
||
},
|
||
root: {
|
||
type: DataTypes.BOOLEAN, // 是否是根节点
|
||
defaultValue: false,
|
||
},
|
||
show: {
|
||
type: DataTypes.BOOLEAN, // 当创建返回的时候,配置是否显示
|
||
defaultValue: true,
|
||
},
|
||
uid: {
|
||
type: DataTypes.STRING,
|
||
allowNull: true,
|
||
},
|
||
},
|
||
{
|
||
sequelize, // 传入 Sequelize 实例
|
||
modelName: 'chat_history', // 模型名称
|
||
},
|
||
);
|
||
|
||
// force 只能run一次,否则会删除表
|
||
ChatHistory.sync({ alter: true, force: true, logging: false }).catch((e) => {
|
||
console.error('History sync error', e);
|
||
});
|