From f4e613724702acd346dd4f78fc313b7b7532b76f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daphn=C3=A9=20Popin?= Date: Fri, 8 Sep 2023 18:10:35 +0200 Subject: [PATCH] Agent config: update models (#1332) * Agent config: update models * Rename full config * replace hasMany --- .../lib/models/assistant/actions/retrieval.ts | 42 +++++++++---------- front/lib/models/assistant/agent.ts | 23 +++++----- 2 files changed, 31 insertions(+), 34 deletions(-) diff --git a/front/lib/models/assistant/actions/retrieval.ts b/front/lib/models/assistant/actions/retrieval.ts index f12372810306..238057dab3f8 100644 --- a/front/lib/models/assistant/actions/retrieval.ts +++ b/front/lib/models/assistant/actions/retrieval.ts @@ -29,8 +29,6 @@ export class AgentRetrievalConfiguration extends Model< declare relativeTimeFrameDuration: number | null; declare relativeTimeFrameUnit: TimeframeUnit | null; declare topK: number; - - declare agentId: ForeignKey; } AgentRetrievalConfiguration.init( { @@ -117,9 +115,6 @@ export class AgentDataSourceConfiguration extends Model< declare createdAt: CreationOptional; declare updatedAt: CreationOptional; - declare timeframeDuration: number | null; - declare timeframeUnit: TimeframeUnit | null; - declare tagsIn: string[] | null; declare tagsNotIn: string[] | null; declare parentsIn: string[] | null; @@ -147,14 +142,6 @@ AgentDataSourceConfiguration.init( allowNull: false, defaultValue: DataTypes.NOW, }, - timeframeDuration: { - type: DataTypes.INTEGER, - allowNull: true, - }, - timeframeUnit: { - type: DataTypes.STRING, - allowNull: true, - }, tagsIn: { type: DataTypes.ARRAY(DataTypes.STRING), allowNull: true, @@ -178,27 +165,36 @@ AgentDataSourceConfiguration.init( hooks: { beforeValidate: (dataSourceConfig: AgentDataSourceConfiguration) => { if ( - (dataSourceConfig.timeframeDuration === null) !== - (dataSourceConfig.timeframeUnit === null) + (dataSourceConfig.tagsIn === null) !== + (dataSourceConfig.tagsNotIn === null) ) { - throw new Error( - "Timeframe duration/unit must be both set or both null" - ); + throw new Error("Tags must be both set or both null"); + } + if ( + (dataSourceConfig.parentsIn === null) !== + (dataSourceConfig.parentsNotIn === null) + ) { + throw new Error("Parents must be both set or both null"); } }, }, } ); -// Retrieval config <> data source config +// Agent config <> Retrieval config +AgentRetrievalConfiguration.hasOne(AgentConfiguration, { + foreignKey: { name: "retrievalConfigurationId", allowNull: true }, // null = no retrieval action set for this Agent +}); + +// Retrieval config <> Data source config AgentRetrievalConfiguration.hasMany(AgentDataSourceConfiguration, { - foreignKey: { name: "retrievalId", allowNull: false }, + foreignKey: { name: "retrievalConfigurationId", allowNull: false }, onDelete: "CASCADE", }); -// Agent config <> Retrieval config -AgentConfiguration.hasOne(AgentRetrievalConfiguration, { - foreignKey: { name: "agentId", allowNull: true }, // null = no generation set for this Agent +// Data source config <> Data source +DataSource.hasMany(AgentDataSourceConfiguration, { + foreignKey: { name: "dataSourceId", allowNull: false }, onDelete: "CASCADE", }); diff --git a/front/lib/models/assistant/agent.ts b/front/lib/models/assistant/agent.ts index c10393cceac4..18e1dfc74442 100644 --- a/front/lib/models/assistant/agent.ts +++ b/front/lib/models/assistant/agent.ts @@ -30,11 +30,15 @@ export class AgentConfiguration extends Model< declare status: AgentConfigurationStatus; declare name: string; declare pictureUrl: string | null; - declare scope: AgentConfigurationScope; - declare workspaceId: ForeignKey | null; // null = it's a global agent - declare model: ForeignKey | null; + declare workspaceId: ForeignKey | null; // null = it's a global agent + declare generationConfigurationId: ForeignKey< + AgentGenerationConfiguration["id"] + > | null; + declare retrievalConfigurationId: ForeignKey< + AgentRetrievalConfiguration["id"] + > | null; } AgentConfiguration.init( { @@ -113,10 +117,8 @@ export class AgentGenerationConfiguration extends Model< declare updatedAt: CreationOptional; declare prompt: string; - declare modelProvider: string; + declare providerId: string; declare modelId: string; - - declare agentId: ForeignKey; } AgentGenerationConfiguration.init( { @@ -139,7 +141,7 @@ AgentGenerationConfiguration.init( type: DataTypes.TEXT, allowNull: false, }, - modelProvider: { + providerId: { type: DataTypes.STRING, allowNull: false, }, @@ -154,14 +156,13 @@ AgentGenerationConfiguration.init( } ); -// Workspace <> Agent config +// Agent config <> Workspace Workspace.hasMany(AgentConfiguration, { foreignKey: { name: "workspaceId", allowNull: true }, // null = global Agent onDelete: "CASCADE", }); // Agent config <> Generation config -AgentConfiguration.hasOne(AgentGenerationConfiguration, { - foreignKey: { name: "agentId", allowNull: false }, // null = no retrieval action set for this Agent - onDelete: "CASCADE", +AgentGenerationConfiguration.hasOne(AgentConfiguration, { + foreignKey: { name: "generationConfigurationId", allowNull: true }, // null = no generation set for this Agent });