145 lines
4.0 KiB
JavaScript
145 lines
4.0 KiB
JavaScript
const Sequelize = require('sequelize');
|
||
const { DataTypes } = Sequelize;
|
||
|
||
module.exports = (sequelize) => {
|
||
const AiCallRecords = sequelize.define('ai_call_records', {
|
||
id: {
|
||
type: DataTypes.INTEGER(11),
|
||
allowNull: false,
|
||
primaryKey: true,
|
||
autoIncrement: true,
|
||
comment: '主键ID'
|
||
},
|
||
user_id: {
|
||
type: DataTypes.INTEGER(11),
|
||
allowNull: true,
|
||
comment: '用户ID'
|
||
},
|
||
sn_code: {
|
||
type: DataTypes.STRING(100),
|
||
allowNull: true,
|
||
comment: '设备SN码'
|
||
},
|
||
service_type: {
|
||
type: DataTypes.STRING(50),
|
||
allowNull: false,
|
||
comment: '服务类型:chat/completion/embedding'
|
||
},
|
||
model_name: {
|
||
type: DataTypes.STRING(100),
|
||
allowNull: false,
|
||
comment: '模型名称'
|
||
},
|
||
prompt_tokens: {
|
||
type: DataTypes.INTEGER(11),
|
||
allowNull: false,
|
||
defaultValue: 0,
|
||
comment: '输入Token数'
|
||
},
|
||
completion_tokens: {
|
||
type: DataTypes.INTEGER(11),
|
||
allowNull: false,
|
||
defaultValue: 0,
|
||
comment: '输出Token数'
|
||
},
|
||
total_tokens: {
|
||
type: DataTypes.INTEGER(11),
|
||
allowNull: false,
|
||
defaultValue: 0,
|
||
comment: '总Token数'
|
||
},
|
||
request_content: {
|
||
type: DataTypes.TEXT,
|
||
allowNull: true,
|
||
comment: '请求内容'
|
||
},
|
||
response_content: {
|
||
type: DataTypes.TEXT,
|
||
allowNull: true,
|
||
comment: '响应内容'
|
||
},
|
||
cost_amount: {
|
||
type: DataTypes.DECIMAL(10, 4),
|
||
allowNull: true,
|
||
comment: '费用(元)'
|
||
},
|
||
status: {
|
||
type: DataTypes.STRING(20),
|
||
allowNull: false,
|
||
defaultValue: 'success',
|
||
comment: '状态:success/failed'
|
||
},
|
||
error_message: {
|
||
type: DataTypes.TEXT,
|
||
allowNull: true,
|
||
comment: '错误信息'
|
||
},
|
||
response_time: {
|
||
type: DataTypes.INTEGER(11),
|
||
allowNull: true,
|
||
comment: '响应时间(毫秒)'
|
||
},
|
||
api_provider: {
|
||
type: DataTypes.STRING(50),
|
||
allowNull: true,
|
||
defaultValue: 'qwen',
|
||
comment: 'API提供商'
|
||
},
|
||
business_type: {
|
||
type: DataTypes.STRING(50),
|
||
allowNull: true,
|
||
comment: '业务类型'
|
||
},
|
||
reference_id: {
|
||
type: DataTypes.STRING(100),
|
||
allowNull: true,
|
||
comment: '关联业务ID'
|
||
},
|
||
create_time: {
|
||
type: DataTypes.DATE,
|
||
allowNull: false,
|
||
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP'),
|
||
comment: '创建时间'
|
||
},
|
||
last_modify_time: {
|
||
type: DataTypes.DATE,
|
||
allowNull: false,
|
||
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'),
|
||
comment: '最后修改时间'
|
||
},
|
||
is_delete: {
|
||
type: DataTypes.TINYINT(1),
|
||
allowNull: false,
|
||
defaultValue: 0,
|
||
comment: '是否删除:0-否,1-是'
|
||
}
|
||
}, {
|
||
tableName: 'ai_call_records',
|
||
timestamps: false,
|
||
indexes: [
|
||
{
|
||
name: 'idx_user_id',
|
||
fields: ['user_id']
|
||
},
|
||
{
|
||
name: 'idx_sn_code',
|
||
fields: ['sn_code']
|
||
},
|
||
{
|
||
name: 'idx_create_time',
|
||
fields: ['create_time']
|
||
},
|
||
{
|
||
name: 'idx_is_delete',
|
||
fields: ['is_delete']
|
||
},
|
||
{
|
||
name: 'idx_business_type',
|
||
fields: ['business_type']
|
||
}
|
||
]
|
||
});
|
||
|
||
return AiCallRecords;
|
||
};
|