39410-vm/backend/src/db/models/system_prompts.js
2026-03-31 02:43:50 +00:00

134 lines
1.7 KiB
JavaScript

const config = require('../../config');
const providers = config.providers;
const crypto = require('crypto');
const bcrypt = require('bcrypt');
const moment = require('moment');
module.exports = function(sequelize, DataTypes) {
const system_prompts = sequelize.define(
'system_prompts',
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
name: {
type: DataTypes.TEXT,
},
prompt_text: {
type: DataTypes.TEXT,
},
tone: {
type: DataTypes.ENUM,
values: [
"dark",
"neutral",
"direct",
"sarcastic"
],
},
is_default: {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: false,
},
is_active: {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: false,
},
importHash: {
type: DataTypes.STRING(255),
allowNull: true,
unique: true,
},
},
{
timestamps: true,
paranoid: true,
freezeTableName: true,
},
);
system_prompts.associate = (db) => {
/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity
db.system_prompts.hasMany(db.chat_sessions, {
as: 'chat_sessions_system_prompt',
foreignKey: {
name: 'system_promptId',
},
constraints: false,
});
//end loop
db.system_prompts.belongsTo(db.users, {
as: 'createdBy',
});
db.system_prompts.belongsTo(db.users, {
as: 'updatedBy',
});
};
return system_prompts;
};