Files
plates-server/src/ai-coach/models/ai-message.model.ts

73 lines
1.4 KiB
TypeScript
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.

import { BelongsTo, Column, DataType, ForeignKey, Model, PrimaryKey, Table } from 'sequelize-typescript';
import { AiConversation } from './ai-conversation.model';
export enum RoleType {
System = 'system',
User = 'user',
Assistant = 'assistant',
}
@Table({
tableName: 't_ai_messages',
underscored: true,
})
export class AiMessage extends Model {
@PrimaryKey
@Column({
type: DataType.BIGINT,
autoIncrement: true,
})
declare id: number;
@ForeignKey(() => AiConversation)
@Column({
type: DataType.STRING,
allowNull: false,
comment: '会话ID',
})
declare conversationId: string;
@Column({
type: DataType.STRING,
allowNull: false,
comment: '用户ID',
})
declare userId: string;
@Column({
type: DataType.ENUM('system', 'user', 'assistant'),
allowNull: false,
})
declare role: RoleType;
@Column({
type: DataType.TEXT('long'),
allowNull: false,
})
declare content: string;
@Column({
type: DataType.JSON,
allowNull: true,
comment: '扩展元数据如token用量、模型名等',
})
declare metadata: Record<string, any> | null;
@Column({
type: DataType.DATE,
defaultValue: DataType.NOW,
})
declare createdAt: Date;
@Column({
type: DataType.DATE,
defaultValue: DataType.NOW,
})
declare updatedAt: Date;
@BelongsTo(() => AiConversation)
declare conversation?: AiConversation;
}