Skip to content

Commit

Permalink
Agent config: update models (#1332)
Browse files Browse the repository at this point in the history
* Agent config: update models

* Rename full config

* replace hasMany
  • Loading branch information
PopDaph authored Sep 8, 2023
1 parent 7a20e7e commit f4e6137
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 34 deletions.
42 changes: 19 additions & 23 deletions front/lib/models/assistant/actions/retrieval.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ export class AgentRetrievalConfiguration extends Model<
declare relativeTimeFrameDuration: number | null;
declare relativeTimeFrameUnit: TimeframeUnit | null;
declare topK: number;

declare agentId: ForeignKey<AgentConfiguration["id"]>;
}
AgentRetrievalConfiguration.init(
{
Expand Down Expand Up @@ -117,9 +115,6 @@ export class AgentDataSourceConfiguration extends Model<
declare createdAt: CreationOptional<Date>;
declare updatedAt: CreationOptional<Date>;

declare timeframeDuration: number | null;
declare timeframeUnit: TimeframeUnit | null;

declare tagsIn: string[] | null;
declare tagsNotIn: string[] | null;
declare parentsIn: string[] | null;
Expand Down Expand Up @@ -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,
Expand All @@ -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",
});

Expand Down
23 changes: 12 additions & 11 deletions front/lib/models/assistant/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Workspace["id"]> | null; // null = it's a global agent

declare model: ForeignKey<AgentRetrievalConfiguration["id"]> | null;
declare workspaceId: ForeignKey<Workspace["id"]> | null; // null = it's a global agent
declare generationConfigurationId: ForeignKey<
AgentGenerationConfiguration["id"]
> | null;
declare retrievalConfigurationId: ForeignKey<
AgentRetrievalConfiguration["id"]
> | null;
}
AgentConfiguration.init(
{
Expand Down Expand Up @@ -113,10 +117,8 @@ export class AgentGenerationConfiguration extends Model<
declare updatedAt: CreationOptional<Date>;

declare prompt: string;
declare modelProvider: string;
declare providerId: string;
declare modelId: string;

declare agentId: ForeignKey<AgentConfiguration["id"]>;
}
AgentGenerationConfiguration.init(
{
Expand All @@ -139,7 +141,7 @@ AgentGenerationConfiguration.init(
type: DataTypes.TEXT,
allowNull: false,
},
modelProvider: {
providerId: {
type: DataTypes.STRING,
allowNull: false,
},
Expand All @@ -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
});

0 comments on commit f4e6137

Please sign in to comment.