129 lines
1.7 KiB
JavaScript
129 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 ai_models = sequelize.define(
|
|
'ai_models',
|
|
{
|
|
id: {
|
|
type: DataTypes.UUID,
|
|
defaultValue: DataTypes.UUIDV4,
|
|
primaryKey: true,
|
|
},
|
|
|
|
name: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
provider: {
|
|
type: DataTypes.ENUM,
|
|
|
|
|
|
|
|
values: [
|
|
|
|
"openai",
|
|
|
|
|
|
"anthropic",
|
|
|
|
|
|
"local",
|
|
|
|
|
|
"custom"
|
|
|
|
],
|
|
|
|
},
|
|
|
|
model: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
description: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
importHash: {
|
|
type: DataTypes.STRING(255),
|
|
allowNull: true,
|
|
unique: true,
|
|
},
|
|
},
|
|
{
|
|
timestamps: true,
|
|
paranoid: true,
|
|
freezeTableName: true,
|
|
},
|
|
);
|
|
|
|
ai_models.associate = (db) => {
|
|
|
|
|
|
/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
db.ai_models.hasMany(db.drafts, {
|
|
as: 'drafts_ai_model',
|
|
foreignKey: {
|
|
name: 'ai_modelId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
|
|
//end loop
|
|
|
|
|
|
|
|
|
|
|
|
db.ai_models.hasMany(db.file, {
|
|
as: 'configuration',
|
|
foreignKey: 'belongsToId',
|
|
constraints: false,
|
|
scope: {
|
|
belongsTo: db.ai_models.getTableName(),
|
|
belongsToColumn: 'configuration',
|
|
},
|
|
});
|
|
|
|
|
|
db.ai_models.belongsTo(db.users, {
|
|
as: 'createdBy',
|
|
});
|
|
|
|
db.ai_models.belongsTo(db.users, {
|
|
as: 'updatedBy',
|
|
});
|
|
};
|
|
|
|
|
|
|
|
return ai_models;
|
|
};
|
|
|
|
|