feat: add agent

This commit is contained in:
2024-09-27 23:03:30 +08:00
parent cfdf2ba00d
commit 718322ae47
16 changed files with 446 additions and 43 deletions

85
src/models/agent.ts Normal file
View File

@@ -0,0 +1,85 @@
import { sequelize } from '@/modules/sequelize.ts';
import { DataTypes, Model } from 'sequelize';
export class AiAgent extends Model {
id: string;
type: string;
model: string;
baseUrl: string;
apiKey: string;
temperature: number;
cache: string;
cacheName: string;
status: string;
data: any;
key: string;
}
// 获取AIAgent的属性
export type AiProperties = {
id: string;
type: string;
model: string;
baseUrl: string;
apiKey?: string;
temperature?: number;
cache?: string;
cacheName?: string;
data?: any;
};
AiAgent.init(
{
id: {
type: DataTypes.UUID,
primaryKey: true,
defaultValue: DataTypes.UUIDV4,
},
type: {
type: DataTypes.STRING,
allowNull: false,
},
status: {
type: DataTypes.STRING,
defaultValue: 'open',
},
model: {
type: DataTypes.STRING,
allowNull: false,
},
baseUrl: {
type: DataTypes.STRING,
allowNull: false,
},
apiKey: {
type: DataTypes.STRING,
allowNull: false,
},
key: {
type: DataTypes.STRING,
},
temperature: {
type: DataTypes.FLOAT,
allowNull: true,
},
cache: {
type: DataTypes.STRING,
allowNull: true,
},
cacheName: {
type: DataTypes.STRING,
allowNull: true,
},
data: {
type: DataTypes.JSON,
allowNull: true,
defaultValue: {},
},
},
{
sequelize,
tableName: 'ai_agent',
},
);
AiAgent.sync({ alter: true, logging: false }).catch((e) => {
console.error('AiAgent sync error', e);
});