generated from tailored/app-template
100 lines
2.0 KiB
TypeScript
100 lines
2.0 KiB
TypeScript
import { sequelize } from '@/modules/sequelize.ts';
|
|
import { DataTypes, Model } from 'sequelize';
|
|
|
|
export type AiChatHistory = Partial<InstanceType<typeof AiChatHistoryModel>>;
|
|
|
|
export type ChastHistoryMessage = {
|
|
role: string;
|
|
content: string;
|
|
name: string;
|
|
id?: string;
|
|
createdAt?: number;
|
|
updatedAt?: number;
|
|
hide?: boolean;
|
|
noUse?: boolean;
|
|
};
|
|
type AiChatHistoryData = {
|
|
hook?: {
|
|
[key: string]: any;
|
|
};
|
|
};
|
|
export class AiChatHistoryModel extends Model {
|
|
declare id: string;
|
|
declare username: string;
|
|
declare model: string;
|
|
declare group: string;
|
|
|
|
declare title: string;
|
|
|
|
declare messages: ChastHistoryMessage[];
|
|
declare uid: string;
|
|
declare data: AiChatHistoryData;
|
|
declare prompt_tokens: number;
|
|
declare total_tokens: number;
|
|
declare completion_tokens: number;
|
|
|
|
declare createdAt: Date;
|
|
declare updatedAt: Date;
|
|
}
|
|
|
|
AiChatHistoryModel.init(
|
|
{
|
|
id: {
|
|
type: DataTypes.UUID,
|
|
primaryKey: true,
|
|
defaultValue: DataTypes.UUIDV4,
|
|
},
|
|
username: {
|
|
type: DataTypes.STRING,
|
|
allowNull: false,
|
|
},
|
|
model: {
|
|
type: DataTypes.STRING,
|
|
allowNull: false,
|
|
},
|
|
group: {
|
|
type: DataTypes.STRING,
|
|
allowNull: false,
|
|
},
|
|
title: {
|
|
type: DataTypes.STRING,
|
|
allowNull: false,
|
|
defaultValue: '',
|
|
},
|
|
messages: {
|
|
type: DataTypes.JSONB,
|
|
allowNull: false,
|
|
defaultValue: [],
|
|
},
|
|
prompt_tokens: {
|
|
type: DataTypes.INTEGER,
|
|
defaultValue: 0,
|
|
},
|
|
total_tokens: {
|
|
type: DataTypes.INTEGER,
|
|
defaultValue: 0,
|
|
},
|
|
completion_tokens: {
|
|
type: DataTypes.INTEGER,
|
|
defaultValue: 0,
|
|
},
|
|
data: {
|
|
type: DataTypes.JSONB,
|
|
defaultValue: {},
|
|
},
|
|
uid: {
|
|
type: DataTypes.UUID,
|
|
allowNull: true,
|
|
},
|
|
},
|
|
{
|
|
sequelize,
|
|
tableName: 'kv_ai_chat_history',
|
|
paranoid: false,
|
|
},
|
|
);
|
|
|
|
AiChatHistoryModel.sync({ alter: true, logging: false }).catch((e) => {
|
|
console.error('AiChatHistoryModel sync', e);
|
|
});
|