code-center/src/models/chat-history.ts
2024-09-30 01:39:07 +08:00

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