38875-vm/backend/src/db/models/llm_runs.js
2026-02-28 15:25:22 +00:00

176 lines
2.0 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 llm_runs = sequelize.define(
'llm_runs',
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
provider: {
type: DataTypes.TEXT,
},
model: {
type: DataTypes.TEXT,
},
prompt_version: {
type: DataTypes.TEXT,
},
input_hash: {
type: DataTypes.TEXT,
},
cache_hit: {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: false,
},
prompt_tokens: {
type: DataTypes.INTEGER,
},
completion_tokens: {
type: DataTypes.INTEGER,
},
cost_usd: {
type: DataTypes.DECIMAL,
},
latency_ms: {
type: DataTypes.INTEGER,
},
status: {
type: DataTypes.ENUM,
values: [
"succeeded",
"failed"
],
},
error_message: {
type: DataTypes.TEXT,
},
run_at: {
type: DataTypes.DATE,
},
importHash: {
type: DataTypes.STRING(255),
allowNull: true,
unique: true,
},
},
{
timestamps: true,
paranoid: true,
freezeTableName: true,
},
);
llm_runs.associate = (db) => {
/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity
//end loop
db.llm_runs.belongsTo(db.analyses, {
as: 'analysis',
foreignKey: {
name: 'analysisId',
},
constraints: false,
});
db.llm_runs.belongsTo(db.users, {
as: 'createdBy',
});
db.llm_runs.belongsTo(db.users, {
as: 'updatedBy',
});
};
return llm_runs;
};