Files
autoAiWorkSys/api/model/ai_call_records.js
张成 43f7884e52 1
2025-12-27 20:14:40 +08:00

143 lines
3.4 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
const Sequelize = require('sequelize');
/**
* AI调用记录表模型
* 记录所有AI API调用的详细信息和Token使用情况
*/
module.exports = (db) => {
const ai_call_records = db.define("ai_call_records", {
user_id: {
comment: '用户ID如果是用户触发的调用',
type: Sequelize.INTEGER,
allowNull: true,
defaultValue: null
},
sn_code: {
comment: '设备序列号',
type: Sequelize.STRING(50),
allowNull: true,
defaultValue: null
},
service_type: {
comment: '服务类型chat, completion, embedding等',
type: Sequelize.STRING(50),
allowNull: false,
defaultValue: ''
},
model_name: {
comment: 'AI模型名称gpt-4, gpt-3.5-turbo等',
type: Sequelize.STRING(100),
allowNull: false,
defaultValue: ''
},
prompt_tokens: {
comment: '输入Token数量',
type: Sequelize.INTEGER,
allowNull: false,
defaultValue: 0
},
completion_tokens: {
comment: '输出Token数量',
type: Sequelize.INTEGER,
allowNull: false,
defaultValue: 0
},
total_tokens: {
comment: '总Token数量',
type: Sequelize.INTEGER,
allowNull: false,
defaultValue: 0
},
request_content: {
comment: '请求内容用户输入的prompt',
type: Sequelize.TEXT,
allowNull: true,
defaultValue: null
},
response_content: {
comment: '响应内容AI返回的结果',
type: Sequelize.TEXT,
allowNull: true,
defaultValue: null
},
cost_amount: {
comment: '本次调用费用(元)',
type: Sequelize.DECIMAL(10, 4),
allowNull: true,
defaultValue: null
},
status: {
comment: '调用状态success=成功, failed=失败, timeout=超时)',
type: Sequelize.STRING(20),
allowNull: false,
defaultValue: 'success'
},
error_message: {
comment: '错误信息(如果调用失败)',
type: Sequelize.TEXT,
allowNull: true,
defaultValue: null
},
response_time: {
comment: '响应时间(毫秒)',
type: Sequelize.INTEGER,
allowNull: true,
defaultValue: null
},
api_provider: {
comment: 'API提供商openai, azure, anthropic等',
type: Sequelize.STRING(50),
allowNull: false,
defaultValue: 'openai'
},
business_type: {
comment: '业务类型job_filter, chat, resume_optimization等',
type: Sequelize.STRING(50),
allowNull: true,
defaultValue: null
},
reference_id: {
comment: '关联业务ID如job_posting_id, chat_record_id等',
type: Sequelize.INTEGER,
allowNull: true,
defaultValue: null
},
}, {
timestamps: false,
indexes: [
{
unique: false,
fields: ['user_id']
},
{
unique: false,
fields: ['sn_code']
},
{
unique: false,
fields: ['service_type']
},
{
unique: false,
fields: ['status']
},
{
unique: false,
fields: ['create_time']
},
{
unique: false,
fields: ['business_type']
},
{
unique: false,
fields: ['reference_id']
}
]
});
// ai_call_records.sync({ force: true });
return ai_call_records;
}