229 lines
2.7 KiB
JavaScript
229 lines
2.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 tool_runs = sequelize.define(
|
|
'tool_runs',
|
|
{
|
|
id: {
|
|
type: DataTypes.UUID,
|
|
defaultValue: DataTypes.UUIDV4,
|
|
primaryKey: true,
|
|
},
|
|
|
|
input_mode: {
|
|
type: DataTypes.ENUM,
|
|
|
|
|
|
|
|
values: [
|
|
|
|
"text",
|
|
|
|
|
|
"voice",
|
|
|
|
|
|
"file"
|
|
|
|
],
|
|
|
|
},
|
|
|
|
input_text: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
model_quality: {
|
|
type: DataTypes.ENUM,
|
|
|
|
|
|
|
|
values: [
|
|
|
|
"basic",
|
|
|
|
|
|
"advanced"
|
|
|
|
],
|
|
|
|
},
|
|
|
|
prompt_tokens: {
|
|
type: DataTypes.INTEGER,
|
|
|
|
|
|
|
|
},
|
|
|
|
output_tokens: {
|
|
type: DataTypes.INTEGER,
|
|
|
|
|
|
|
|
},
|
|
|
|
cost_estimate: {
|
|
type: DataTypes.DECIMAL,
|
|
|
|
|
|
|
|
},
|
|
|
|
run_status: {
|
|
type: DataTypes.ENUM,
|
|
|
|
|
|
|
|
values: [
|
|
|
|
"queued",
|
|
|
|
|
|
"running",
|
|
|
|
|
|
"succeeded",
|
|
|
|
|
|
"failed",
|
|
|
|
|
|
"cancelled"
|
|
|
|
],
|
|
|
|
},
|
|
|
|
error_message: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
started_at: {
|
|
type: DataTypes.DATE,
|
|
|
|
|
|
|
|
},
|
|
|
|
finished_at: {
|
|
type: DataTypes.DATE,
|
|
|
|
|
|
|
|
},
|
|
|
|
importHash: {
|
|
type: DataTypes.STRING(255),
|
|
allowNull: true,
|
|
unique: true,
|
|
},
|
|
},
|
|
{
|
|
timestamps: true,
|
|
paranoid: true,
|
|
freezeTableName: true,
|
|
},
|
|
);
|
|
|
|
tool_runs.associate = (db) => {
|
|
|
|
|
|
/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
db.tool_runs.hasMany(db.voice_recordings, {
|
|
as: 'voice_recordings_tool_run',
|
|
foreignKey: {
|
|
name: 'tool_runId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//end loop
|
|
|
|
|
|
|
|
db.tool_runs.belongsTo(db.users, {
|
|
as: 'user',
|
|
foreignKey: {
|
|
name: 'userId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.tool_runs.belongsTo(db.ai_tools, {
|
|
as: 'tool',
|
|
foreignKey: {
|
|
name: 'toolId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.tool_runs.belongsTo(db.documents, {
|
|
as: 'document',
|
|
foreignKey: {
|
|
name: 'documentId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
db.tool_runs.hasMany(db.file, {
|
|
as: 'input_file',
|
|
foreignKey: 'belongsToId',
|
|
constraints: false,
|
|
scope: {
|
|
belongsTo: db.tool_runs.getTableName(),
|
|
belongsToColumn: 'input_file',
|
|
},
|
|
});
|
|
|
|
|
|
db.tool_runs.belongsTo(db.users, {
|
|
as: 'createdBy',
|
|
});
|
|
|
|
db.tool_runs.belongsTo(db.users, {
|
|
as: 'updatedBy',
|
|
});
|
|
};
|
|
|
|
|
|
|
|
return tool_runs;
|
|
};
|
|
|
|
|